code cleanup

This commit is contained in:
FalsePattern committed 2022-07-31 20:41:56 +02:00
1 parent eaec528f5d
commit 316908baae
76 files changed
+691 -622

No files matched your search

@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -27,6 +27,7 @@ import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.Name;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.SortingIndex;
import java.util.Map;
/**
@@ -39,6 +40,16 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
@Getter
private static boolean obfuscated;
static {
try {
Class.forName("thermos.Thermos");
throw skillIssue("Thermos is not supported by FalsePatternLib, please use a normal forge server.");
} catch (ClassNotFoundException ignored) {
}
}
@SuppressWarnings("SameParameterValue")
private static Error skillIssue(String message) {
int width = message.length();
String shutup = "Any bug reports concerning this message will be silently deleted.";
@@ -87,13 +98,6 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
skillIssue.setStackTrace(new StackTraceElement[0]);
return skillIssue;
}
static {
try {
Class.forName("thermos.Thermos");
throw skillIssue("Thermos is not supported by FalsePatternLib, please use a normal forge server.");
} catch (ClassNotFoundException ignored) {}
}
@Override
public String[] getASMTransformerClass() {
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -21,21 +21,19 @@
package com.falsepattern.lib.internal;
import com.falsepattern.lib.internal.proxy.CommonProxy;
import lombok.Getter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import cpw.mods.fml.common.*;
import net.minecraft.launchwrapper.Launch;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import lombok.Getter;
import net.minecraft.launchwrapper.Launch;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Utility class used by FalsePatternLib's internal code. This can change between versions without notice, so do not use
* this in your code!
@@ -50,12 +48,14 @@ public class FalsePatternLib {
public static final String UPDATE_URL = "https://falsepattern.com/mc/versions.json";
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(Tags.MODID);
@Getter private static final Logger log = LogManager.getLogger(Tags.MODNAME);
@Getter
private static final Logger log = LogManager.getLogger(Tags.MODNAME);
@Getter private static final boolean developerEnvironment =
(boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
@Getter
private static final boolean developerEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
@SidedProxy(clientSide = Tags.GROUPNAME + ".internal.proxy.ClientProxy", serverSide = Tags.GROUPNAME + ".internal.proxy.CommonProxy")
@SidedProxy(clientSide = Tags.GROUPNAME + ".internal.proxy.ClientProxy",
serverSide = Tags.GROUPNAME + ".internal.proxy.CommonProxy")
private static CommonProxy proxy;
public FalsePatternLib() {
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -23,7 +23,10 @@ package com.falsepattern.lib.internal;
import lombok.val;
import lombok.var;
import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.CompletableFuture;
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -19,6 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal;
import lombok.Getter;
import java.io.IOException;
@@ -32,8 +33,81 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
@SuppressWarnings("ALL")
@Getter
class SRGGen {
private static final Map<String, String> class_notch_srg = new HashMap<>();
private static final Map<String, String> class_notch_mcp = new HashMap<>();
private static final Map<String, String> class_srg_mcp = new HashMap<>();
private static final Map<String, String> class_mcp_srg = new HashMap<>();
private static final Map<String, String> class_mcp_notch = new HashMap<>();
private static final Map<String, String> field_notch_srg = new HashMap<>();
private static final Map<String, String> field_notch_mcp = new HashMap<>();
private static final Map<String, String> field_srg_mcp = new HashMap<>();
private static final Map<String, String> field_mcp_srg = new HashMap<>();
private static final Map<String, String> field_mcp_notch = new HashMap<>();
private static final Map<StringPair, StringPair> method_notch_srg = new HashMap<>();
private static final Map<StringPair, StringPair> method_notch_mcp = new HashMap<>();
private static final Map<StringPair, StringPair> method_srg_mcp = new HashMap<>();
private static final Map<StringPair, StringPair> method_mcp_srg = new HashMap<>();
private static final Map<StringPair, StringPair> method_mcp_notch = new HashMap<>();
public static void main(String[] args) throws IOException {
Path dir = Paths.get(args[0]);
parseLines(Files.readAllLines(dir.resolve("notch-srg.srg")), class_notch_srg, field_notch_srg,
method_notch_srg);
parseLines(Files.readAllLines(dir.resolve("notch-mcp.srg")), class_notch_mcp, field_notch_mcp,
method_notch_mcp);
parseLines(Files.readAllLines(dir.resolve("srg-mcp.srg")), class_srg_mcp, field_srg_mcp, method_srg_mcp);
parseLines(Files.readAllLines(dir.resolve("mcp-srg.srg")), class_mcp_srg, field_mcp_srg, method_mcp_srg);
parseLines(Files.readAllLines(dir.resolve("mcp-notch.srg")), class_mcp_notch, field_mcp_notch,
method_mcp_notch);
try (OutputStream output = Files.newOutputStream(dir.resolve("classes.csv"))) {
output.write("notch,srg,mcp\n".getBytes(StandardCharsets.UTF_8));
crossValidate(class_notch_srg, class_notch_mcp, class_srg_mcp, class_mcp_srg, class_mcp_notch, output);
}
try (OutputStream output = Files.newOutputStream(dir.resolve("fields.csv"))) {
output.write("notch,srg,mcp\n".getBytes(StandardCharsets.UTF_8));
crossValidate(field_notch_srg, field_notch_mcp, field_srg_mcp, field_mcp_srg, field_mcp_notch, output);
}
try (OutputStream output = Files.newOutputStream(dir.resolve("methods.csv"))) {
output.write("notch,notchdesc,srg,srgdesc,mcp,mcpdesc\n".getBytes(StandardCharsets.UTF_8));
crossValidate(method_notch_srg, method_notch_mcp, method_srg_mcp, method_mcp_srg, method_mcp_notch, output);
}
}
private static boolean crossValidate(Map<?, ?> notch_srg, Map<?, ?> notch_mcp, Map<?, ?> srg_mcp, Map<?, ?> mcp_srg, Map<?, ?> mcp_notch, OutputStream output)
throws IOException {
for (Map.Entry<?, ?> notch_srg_entry : notch_srg.entrySet()) {
Object notch = notch_srg_entry.getKey();
Object srg = notch_srg_entry.getValue();
Object mcp = notch_mcp.get(notch);
if (!srg_mcp.get(srg).equals(mcp) || !mcp_srg.get(mcp).equals(srg) || !mcp_notch.get(mcp).equals(notch)) {
throw new RuntimeException(notch + " - " + srg + " - " + mcp);
}
output.write((notch + "," + srg + "," + mcp + "\n").getBytes(StandardCharsets.UTF_8));
}
return true;
}
private static void parseLines(List<String> lines, Map<String, String> classes, Map<String, String> fields, Map<StringPair, StringPair> methods) {
for (String line : lines) {
String[] parts = line.split(" ");
switch (parts[0]) {
case "CL:":
classes.put(parts[1], parts[2]);
break;
case "FD:":
fields.put(parts[1], parts[2]);
break;
case "MD:":
methods.put(new StringPair(parts[1], parts[2]), new StringPair(parts[3], parts[4]));
break;
}
}
}
private static class StringPair {
public final String name;
public final String desc;
@@ -65,73 +139,4 @@ class SRGGen {
return name + "," + desc;
}
}
private static Map<String, String> class_notch_srg = new HashMap<>();
private static Map<String, String> class_notch_mcp = new HashMap<>();
private static Map<String, String> class_srg_mcp = new HashMap<>();
private static Map<String, String> class_mcp_srg = new HashMap<>();
private static Map<String, String> class_mcp_notch = new HashMap<>();
private static Map<String, String> field_notch_srg = new HashMap<>();
private static Map<String, String> field_notch_mcp = new HashMap<>();
private static Map<String, String> field_srg_mcp = new HashMap<>();
private static Map<String, String> field_mcp_srg = new HashMap<>();
private static Map<String, String> field_mcp_notch = new HashMap<>();
private static Map<StringPair, StringPair> method_notch_srg = new HashMap<>();
private static Map<StringPair, StringPair> method_notch_mcp = new HashMap<>();
private static Map<StringPair, StringPair> method_srg_mcp = new HashMap<>();
private static Map<StringPair, StringPair> method_mcp_srg = new HashMap<>();
private static Map<StringPair, StringPair> method_mcp_notch = new HashMap<>();
public static void main(String[] args) throws IOException {
Path dir = Paths.get(args[0]);
parseLines(Files.readAllLines(dir.resolve("notch-srg.srg")), class_notch_srg, field_notch_srg, method_notch_srg);
parseLines(Files.readAllLines(dir.resolve("notch-mcp.srg")), class_notch_mcp, field_notch_mcp, method_notch_mcp);
parseLines(Files.readAllLines(dir.resolve("srg-mcp.srg")), class_srg_mcp, field_srg_mcp, method_srg_mcp);
parseLines(Files.readAllLines(dir.resolve("mcp-srg.srg")), class_mcp_srg, field_mcp_srg, method_mcp_srg);
parseLines(Files.readAllLines(dir.resolve("mcp-notch.srg")), class_mcp_notch, field_mcp_notch, method_mcp_notch);
try (OutputStream output = Files.newOutputStream(dir.resolve("classes.csv"))) {
output.write("notch,srg,mcp\n".getBytes(StandardCharsets.UTF_8));
crossValidate(class_notch_srg, class_notch_mcp, class_srg_mcp, class_mcp_srg, class_mcp_notch, output);
}
try (OutputStream output = Files.newOutputStream(dir.resolve("fields.csv"))) {
output.write("notch,srg,mcp\n".getBytes(StandardCharsets.UTF_8));
crossValidate(field_notch_srg, field_notch_mcp, field_srg_mcp, field_mcp_srg, field_mcp_notch, output);
}
try (OutputStream output = Files.newOutputStream(dir.resolve("methods.csv"))) {
output.write("notch,notchdesc,srg,srgdesc,mcp,mcpdesc\n".getBytes(StandardCharsets.UTF_8));
crossValidate(method_notch_srg, method_notch_mcp, method_srg_mcp, method_mcp_srg, method_mcp_notch, output);
}
}
private static boolean crossValidate(Map<?, ?> notch_srg, Map<?, ?> notch_mcp, Map<?, ?> srg_mcp, Map<?, ?> mcp_srg, Map<?, ?> mcp_notch, OutputStream output)
throws IOException {
for (Map.Entry<?, ?> notch_srg_entry: notch_srg.entrySet()) {
Object notch = notch_srg_entry.getKey();
Object srg = notch_srg_entry.getValue();
Object mcp = notch_mcp.get(notch);
if (!srg_mcp.get(srg).equals(mcp) ||
!mcp_srg.get(mcp).equals(srg) ||
!mcp_notch.get(mcp).equals(notch)) {
throw new RuntimeException(notch + " - " + srg + " - " + mcp);
}
output.write((notch + "," + srg + "," + mcp + "\n").getBytes(StandardCharsets.UTF_8));
}
return true;
}
private static void parseLines(List<String> lines, Map<String, String> classes, Map<String, String> fields, Map<StringPair, StringPair> methods) {
for (String line: lines) {
String[] parts = line.split(" ");
switch (parts[0]) {
case "CL:":
classes.put(parts[1], parts[2]);
break;
case "FD:":
fields.put(parts[1], parts[2]);
break;
case "MD:":
methods.put(new StringPair(parts[1], parts[2]), new StringPair(parts[3], parts[4]));
break;
}
}
}
}
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -45,6 +45,8 @@ public class LibraryConfig {
public static ValidationLogging CONFIG_ERROR_LOUDNESS;
public enum ValidationLogging {
None, Log, LogAndToast
None,
Log,
LogAndToast
}
}
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -24,9 +24,9 @@ import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.SimpleGuiConfig;
import com.falsepattern.lib.internal.Tags;
import net.minecraft.client.gui.GuiScreen;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
@SideOnly(Side.CLIENT)
public class LibraryGuiConfig extends SimpleGuiConfig {
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -21,9 +21,10 @@
package com.falsepattern.lib.internal.config;
import com.falsepattern.lib.config.SimpleGuiFactory;
import net.minecraft.client.gui.GuiScreen;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
@SideOnly(Side.CLIENT)
public class LibraryGuiFactory implements SimpleGuiFactory {
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -54,6 +54,7 @@ public class ToastConfig {
}
public enum Side {
Left, Right
Left,
Right
}
}
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -73,7 +73,7 @@ import java.util.function.BiConsumer;
/**
* The actual implementation of ConfigurationManager. Migrated stuff here so that we don't unnecessarily expose
* internal-use functionality.
*
* <p>
* Do not read if you value your sanity.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@@ -116,7 +116,8 @@ public class ConfigurationManagerImpl {
parsedConfigMap.get(configClass).save();
}
public static boolean validateFields(BiConsumer<Class<?>, Field> invalidFieldHandler, Class<?> configClass, boolean resetInvalid) throws ConfigException {
public static boolean validateFields(BiConsumer<Class<?>, Field> invalidFieldHandler, Class<?> configClass, boolean resetInvalid)
throws ConfigException {
if (!parsedConfigMap.containsKey(configClass)) {
throw new ConfigException("Class " + configClass.getName() + " is not a registered configuration!");
}
@@ -133,13 +134,13 @@ public class ConfigurationManagerImpl {
public static void sendRequest(DataOutput output) throws IOException {
val synced = new ArrayList<Class<?>>();
for (val entry: parsedConfigMap.entrySet()) {
for (val entry : parsedConfigMap.entrySet()) {
if (entry.getValue().sync) {
synced.add(entry.getKey());
}
}
output.writeInt(synced.size());
for (val clazz: synced) {
for (val clazz : synced) {
output.writeUTF(clazz.getName());
}
}
@@ -151,7 +152,7 @@ public class ConfigurationManagerImpl {
for (int i = 0; i < count; i++) {
classNames.add(input.readUTF());
}
for (val entry: parsedConfigMap.keySet()) {
for (val entry : parsedConfigMap.keySet()) {
if (classNames.contains(entry.getName())) {
result.add(entry);
}
@@ -161,13 +162,13 @@ public class ConfigurationManagerImpl {
public static void sendReply(DataOutput output, List<Class<?>> requestedClasses) throws IOException {
val syncEntries = new HashMap<>(parsedConfigMap);
for (val entry: parsedConfigMap.entrySet()) {
for (val entry : parsedConfigMap.entrySet()) {
if (!entry.getValue().sync || !requestedClasses.contains(entry.getKey())) {
syncEntries.remove(entry.getKey());
}
}
output.writeInt(syncEntries.size());
for (val entry: syncEntries.entrySet()) {
for (val entry : syncEntries.entrySet()) {
output.writeUTF(entry.getKey().getName());
val b = new ByteArrayOutputStream();
val bo = new DataOutputStream(b);
@@ -187,7 +188,8 @@ public class ConfigurationManagerImpl {
for (int i = 0; i < count; i++) {
String className = input.readUTF();
int dataSize = input.readInt();
val opt = parsedConfigMap.keySet().stream().filter((clazz) -> clazz.getName().equals(className)).findFirst();
val opt =
parsedConfigMap.keySet().stream().filter((clazz) -> clazz.getName().equals(className)).findFirst();
if (!opt.isPresent()) {
input.skipBytes(dataSize);
FalsePatternLib.getLog().warn("Server tried to sync config not registered on our side: " + className);
@@ -197,7 +199,9 @@ public class ConfigurationManagerImpl {
val config = parsedConfigMap.get(clazz);
if (!config.sync) {
input.skipBytes(dataSize);
FalsePatternLib.getLog().warn("Server tried to sync config without @Synchronize annotation on our side: " + className);
FalsePatternLib.getLog()
.warn("Server tried to sync config without @Synchronize annotation on our side: " +
className);
continue;
}
if (!ConfigSyncEvent.postStart(clazz)) {
@@ -223,11 +227,11 @@ public class ConfigurationManagerImpl {
public static void loadRawConfig(Configuration rawConfig) throws ConfigException {
rawConfig.load();
for (val configClass: configToClassMap.get(rawConfig)) {
for (val configClass : configToClassMap.get(rawConfig)) {
val config = parsedConfigMap.get(configClass);
try {
config.reloadFields();
} catch (NoSuchFieldException | IllegalAccessException e) {
} catch (IllegalAccessException e) {
throw new ConfigException(e);
}
}
@@ -296,7 +300,7 @@ public class ConfigurationManagerImpl {
return;
}
val configClasses = configToClassMap.get(rawConfig);
for (val clazz: configClasses) {
for (val clazz : configClasses) {
val config = parsedConfigMap.get(clazz);
config.configChanged();
}
@@ -323,12 +327,16 @@ public class ConfigurationManagerImpl {
val cfg = e.configClass.getAnnotation(Config.class);
if (e.successful) {
GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, null,
FormattedText.parse(EnumChatFormatting.GREEN + "Synced config").toChatText().get(0),
FormattedText.parse(EnumChatFormatting.GREEN + "Synced config")
.toChatText()
.get(0),
FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0),
false, 5000));
} else {
GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, null,
FormattedText.parse(EnumChatFormatting.RED + "Failed to sync config").toChatText().get(0),
FormattedText.parse(EnumChatFormatting.RED + "Failed to sync config")
.toChatText()
.get(0),
FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0),
false, 5000));
}
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -38,7 +38,6 @@ import lombok.val;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.client.config.IConfigElement;
import java.io.DataInput;
@@ -57,15 +56,6 @@ import java.util.function.BiConsumer;
public class ParsedConfiguration {
private static final Field propField;
public final Class<?> configClass;
public final String modid;
public final String category;
public final Configuration rawConfig;
public final boolean sync;
private final Map<String, AConfigField<?>> fields = new HashMap<>();
private final Map<String, ConfigElement<?>> elements = new HashMap<>();
private int maxFieldNameLength;
static {
try {
propField = ConfigElement.class.getDeclaredField("prop");
@@ -75,6 +65,15 @@ public class ParsedConfiguration {
ReflectionUtil.jailBreak(propField);
}
public final Class<?> configClass;
public final String modid;
public final String category;
public final Configuration rawConfig;
public final boolean sync;
private final Map<String, AConfigField<?>> fields = new HashMap<>();
private final Map<String, ConfigElement<?>> elements = new HashMap<>();
private int maxFieldNameLength;
public static ParsedConfiguration parseConfig(Class<?> configClass) throws ConfigException {
val cfg = Optional.ofNullable(configClass.getAnnotation(Config.class))
.orElseThrow(() -> new ConfigException(
@@ -84,10 +83,11 @@ public class ParsedConfiguration {
.orElseThrow(() -> new ConfigException(
"Config class " + configClass.getName() + " has an empty category!"));
val rawConfig = ConfigurationManagerImpl.getForgeConfig(cfg.modid());
val parsedConfig = new ParsedConfiguration(configClass, cfg.modid(), category, rawConfig, configClass.isAnnotationPresent(Config.Synchronize.class));
val parsedConfig = new ParsedConfiguration(configClass, cfg.modid(), category, rawConfig,
configClass.isAnnotationPresent(Config.Synchronize.class));
try {
parsedConfig.reloadFields();
} catch (NoSuchFieldException | IllegalAccessException e) {
} catch (IllegalAccessException e) {
throw new ConfigException(e);
}
return parsedConfig;
@@ -102,7 +102,7 @@ public class ParsedConfiguration {
//Happens when changed through the gui
public void configChanged() {
for (val field: fields.values()) {
for (val field : fields.values()) {
field.load();
}
rawConfig.save();
@@ -110,7 +110,7 @@ public class ParsedConfiguration {
public void load() throws ConfigException {
ConfigurationManagerImpl.loadRawConfig(rawConfig);
for (val field: fields.values()) {
for (val field : fields.values()) {
field.load();
}
}
@@ -118,15 +118,17 @@ public class ParsedConfiguration {
public void receive(DataInput input) throws IOException {
if (sync) {
val syncFields = new HashMap<>(fields);
for (val key: fields.keySet()) {
for (val key : fields.keySet()) {
if (syncFields.get(key).noSync) {
syncFields.remove(key);
}
}
while (syncFields.size() > 0) {
val fieldName = StringConfigField.receiveString(input, maxFieldNameLength, "field name", configClass.getName());
val fieldName =
StringConfigField.receiveString(input, maxFieldNameLength, "field name", configClass.getName());
if (!syncFields.containsKey(fieldName)) {
throw new IOException("Invalid sync field name received: " + fieldName + " for config class " + configClass.getName());
throw new IOException("Invalid sync field name received: " + fieldName + " for config class " +
configClass.getName());
}
syncFields.remove(fieldName).receive(input);
}
@@ -136,19 +138,19 @@ public class ParsedConfiguration {
public void transmit(DataOutput output) throws IOException {
if (sync) {
val syncFields = new HashMap<>(fields);
for (val key: fields.keySet()) {
for (val key : fields.keySet()) {
if (syncFields.get(key).noSync) {
syncFields.remove(key);
}
}
for (val field: syncFields.entrySet()) {
for (val field : syncFields.entrySet()) {
StringConfigField.transmitString(output, field.getKey());
field.getValue().transmit(output);
}
}
}
public void reloadFields() throws ConfigException, NoSuchFieldException, IllegalAccessException {
public void reloadFields() throws ConfigException, IllegalAccessException {
fields.clear();
maxFieldNameLength = 0;
val cat = rawConfig.getCategory(category);
@@ -209,7 +211,7 @@ public class ParsedConfiguration {
public boolean validate(BiConsumer<Class<?>, Field> invalidFieldHandler, boolean resetInvalid) {
boolean valid = true;
for (val field: fields.values()) {
for (val field : fields.values()) {
if (!field.validateField()) {
if (resetInvalid) {
field.setToDefault();
@@ -102,6 +102,7 @@ public abstract class AConfigField<T> {
return property;
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public abstract boolean validateField();
public abstract void transmit(DataOutput output) throws IOException;
@@ -112,7 +112,8 @@ public class DoubleConfigField extends AConfigField<Double> {
if (value >= min && value <= max) {
return true;
}
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, -1, Double.toString(value), Double.toString(min), Double.toString(max));
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, -1, Double.toString(value),
Double.toString(min), Double.toString(max));
return false;
}
@@ -107,7 +107,8 @@ public class DoubleListConfigField extends AListConfigField<double[]> {
for (int j = 0; j < doubles.length; j++) {
double d = doubles[j];
if (d < min || d > max) {
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, j, Double.toString(d), Double.toString(min), Double.toString(max));
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, j, Double.toString(d),
Double.toString(min), Double.toString(max));
valid = false;
}
}
@@ -57,7 +57,9 @@ public class EnumConfigField<T extends Enum<T>> extends AConfigField<T> {
.stream()
.filter((e) -> e.name().equals(defName))
.findAny()
.orElseThrow(() -> new IllegalArgumentException("Default value \"" + defName + "\" was not found in enum " + enumClass.getName())))
.orElseThrow(() -> new IllegalArgumentException(
"Default value \"" + defName +
"\" was not found in enum " + enumClass.getName())))
.orElseGet(() -> {
FalsePatternLib.getLog()
.warn("The field " + field.getName() + " in class " +
@@ -118,7 +118,8 @@ public class FloatConfigField extends AConfigField<Float> {
if (value >= min && value <= max) {
return true;
}
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, -1, Float.toString(value), Float.toString(min), Float.toString(max));
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, -1, Float.toString(value),
Float.toString(min), Float.toString(max));
return false;
} else {
return true;
@@ -112,7 +112,8 @@ public class IntConfigField extends AConfigField<Integer> {
if (value >= min && value <= max) {
return true;
}
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, -1, Integer.toString(value), Integer.toString(min), Integer.toString(max));
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, -1, Integer.toString(value),
Integer.toString(min), Integer.toString(max));
return false;
}
@@ -107,7 +107,8 @@ public class IntListConfigField extends AListConfigField<int[]> {
for (int j = 0; j < ints.length; j++) {
int i = ints[j];
if (i < min || i > max) {
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, j, Integer.toString(i), Integer.toString(min), Integer.toString(max));
ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, j, Integer.toString(i),
Integer.toString(min), Integer.toString(max));
valid = false;
}
}
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -24,8 +24,8 @@ import com.falsepattern.lib.dependencies.DependencyLoader;
import com.falsepattern.lib.dependencies.Version;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.Internet;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.util.FileUtil;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -66,11 +66,9 @@ public class DependencyLoaderImpl {
mavenRepositories.add(url);
}
public static void loadLibrary(@NonNull String loadingModId, @NonNull String groupId, @NonNull String artifactId,
@NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion,
String regularSuffix, String devSuffix) {
new DependencyLoadTask(loadingModId, groupId, artifactId, minVersion, maxVersion, preferredVersion, regularSuffix, devSuffix)
.load();
public static void loadLibrary(@NonNull String loadingModId, @NonNull String groupId, @NonNull String artifactId, @NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion, String regularSuffix, String devSuffix) {
new DependencyLoadTask(loadingModId, groupId, artifactId, minVersion, maxVersion, preferredVersion,
regularSuffix, devSuffix).load();
}
private static String bytesToHex(byte[] hash) {
@@ -188,8 +186,8 @@ public class DependencyLoaderImpl {
private void setupLibraryNames() {
suffix = FalsePatternLib.isDeveloperEnvironment() ? devSuffix : regularSuffix;
artifactLogName =
String.format("%s:%s:%s%s", groupId, artifactId, preferredVersion, suffix != null ? "-" + suffix : "");
artifactLogName = String.format("%s:%s:%s%s", groupId, artifactId, preferredVersion,
suffix != null ? "-" + suffix : "");
log.info("Adding library {}, requested by mod {}", artifactLogName, loadingModId);
artifact = groupId + ":" + artifactId + ":" + suffix;
}
@@ -230,8 +228,8 @@ public class DependencyLoaderImpl {
}
}
val modsDir = Paths.get(homeDir, "mods").toFile();
mavenJarName = String.format("%s-%s%s.jar", artifactId, preferredVersion,
(suffix != null) ? ("-" + suffix) : "");
mavenJarName =
String.format("%s-%s%s.jar", artifactId, preferredVersion, (suffix != null) ? ("-" + suffix) : "");
jarName = groupId + "-" + mavenJarName;
libDir = new File(modsDir, "falsepattern");
if (!libDir.exists()) {
@@ -244,7 +242,9 @@ public class DependencyLoaderImpl {
}
private boolean tryLoadingExistingFile() {
if (!file.exists()) return false;
if (!file.exists()) {
return false;
}
try {
addToClasspath(file);
loadedLibraries.put(artifact, preferredVersion);
@@ -273,8 +273,8 @@ public class DependencyLoaderImpl {
if (!repo.endsWith("/")) {
repo = repo + "/";
}
val url = String.format("%s%s/%s/%s/%s", repo, groupId.replace('.', '/'), artifactId,
preferredVersion, mavenJarName);
val url = String.format("%s%s/%s/%s/%s", repo, groupId.replace('.', '/'), artifactId, preferredVersion,
mavenJarName);
String finalRepo = repo;
int retryCount = 0;
while (true) {
@@ -283,14 +283,14 @@ public class DependencyLoaderImpl {
break;
}
val success = new AtomicBoolean(false);
Internet.connect(new URL(url), (ex) -> log.debug("Artifact {} could not be downloaded from repo {}: {}",
artifactLogName, finalRepo, ex.getMessage()),
(input) -> {
log.debug("Downloading {} from {}", artifactLogName, finalRepo);
download(input, file);
log.debug("Downloaded {} from {}", artifactLogName, finalRepo);
success.set(true);
});
Internet.connect(new URL(url),
(ex) -> log.debug("Artifact {} could not be downloaded from repo {}: {}",
artifactLogName, finalRepo, ex.getMessage()), (input) -> {
log.debug("Downloading {} from {}", artifactLogName, finalRepo);
download(input, file);
log.debug("Downloaded {} from {}", artifactLogName, finalRepo);
success.set(true);
});
if (success.get()) {
log.debug("Validating checksum for {}", artifactLogName);
val hadChecksum = validateChecksum(url);
@@ -322,13 +322,13 @@ public class DependencyLoaderImpl {
log.debug("Attempting to get {} checksum...", checksumType);
val success = new AtomicBoolean(false);
Internet.connect(new URL(checksumURL),
(ex) -> log.debug("Could not get {} checksum for {}: {}", checksumType, artifactLogName, ex.getMessage()),
(input) -> {
log.debug("Downloading {} checksum for {}", checksumType, artifactLogName);
download(input, checksumFile);
log.debug("Downloaded {} checksum for {}", checksumType, artifactLogName);
success.set(true);
});
(ex) -> log.debug("Could not get {} checksum for {}: {}", checksumType,
artifactLogName, ex.getMessage()), (input) -> {
log.debug("Downloading {} checksum for {}", checksumType, artifactLogName);
download(input, checksumFile);
log.debug("Downloaded {} checksum for {}", checksumType, artifactLogName);
success.set(true);
});
if (success.get()) {
val fileHash = hash(checksumType, file);
val referenceHash = new String(Files.readAllBytes(checksumFile.toPath()));
@@ -347,7 +347,9 @@ public class DependencyLoaderImpl {
}
private enum ChecksumStatus {
OK, FAILED, MISSING
OK,
FAILED,
MISSING
}
}
}
@@ -20,7 +20,6 @@
*/
package com.falsepattern.lib.internal.impl.toast;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.config.ToastConfig;
import com.falsepattern.lib.toasts.IToast;
import com.falsepattern.lib.util.MathUtil;
@@ -45,10 +44,14 @@ import java.util.Deque;
@SideOnly(Side.CLIENT)
public class GuiToastImpl extends Gui {
private static GuiToastImpl instance;
private final Minecraft mc;
private final Deque<IToast> toastsQueue = Queues.newArrayDeque();
private ToastInstance<?>[] visible = new ToastInstance[0];
private static GuiToastImpl instance;
public GuiToastImpl(Minecraft mcIn) {
this.mc = mcIn;
}
public static void initialize(Minecraft mc) {
if (instance != null) {
@@ -64,7 +67,7 @@ public class GuiToastImpl extends Gui {
@SubscribeEvent
public void updateToasts(TickEvent.RenderTickEvent event) {
if ( event.phase != TickEvent.Phase.END) {
if (event.phase != TickEvent.Phase.END) {
return;
}
mc.mcProfiler.startSection("toasts");
@@ -72,11 +75,6 @@ public class GuiToastImpl extends Gui {
mc.mcProfiler.endSection();
}
public GuiToastImpl(Minecraft mcIn) {
this.mc = mcIn;
}
public void drawToast(ScaledResolution resolution) {
if (!this.mc.gameSettings.hideGUI) {
RenderHelper.disableStandardItemLighting();
@@ -168,9 +166,7 @@ public class GuiToastImpl extends Gui {
GL11.glPushMatrix();
val shift = toast.width() * getVisibility(sysTime);
val X = ToastConfig.leftAlign() ? shift - toast.width() : x - shift;
GL11.glTranslatef(X,
(float) (y * 32) + ToastConfig.Y_OFFSET,
(float) (500 + y));
GL11.glTranslatef(X, (float) (y * 32) + ToastConfig.Y_OFFSET, (float) (500 + y));
val visibility = this.toast.draw(GuiToastImpl.this, sysTime - this.visibleTime);
GL11.glPopMatrix();
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -25,10 +25,6 @@ import com.falsepattern.lib.config.ConfigurationManager;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.internal.config.ToastConfig;
import com.falsepattern.lib.internal.impl.config.net.SyncPrompt;
import com.falsepattern.lib.internal.impl.config.net.SyncPromptHandler;
import com.falsepattern.lib.internal.impl.config.net.SyncReply;
import com.falsepattern.lib.internal.impl.config.net.SyncReplyHandler;
import com.falsepattern.lib.internal.impl.toast.GuiToastImpl;
import com.falsepattern.lib.updates.UpdateChecker;
import lombok.val;
@@ -83,11 +79,12 @@ public class ClientProxy extends CommonProxy {
@SubscribeEvent
public void onSinglePlayer(EntityJoinWorldEvent e) {
if (chatFuture == null ||
!(e.entity instanceof EntityPlayerSP)) return;
if (chatFuture == null || !(e.entity instanceof EntityPlayerSP)) {
return;
}
val player = (EntityPlayerSP) e.entity;
try {
for (val line: chatFuture.get()) {
for (val line : chatFuture.get()) {
player.addChatMessage(line);
}
chatFuture = null;
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -24,7 +24,6 @@ import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.ConfigurationManager;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.config.ToastConfig;
import com.falsepattern.lib.internal.impl.config.ConfigurationManagerImpl;
import com.falsepattern.lib.internal.impl.config.net.SyncPrompt;
import com.falsepattern.lib.internal.impl.config.net.SyncPromptHandler;
@@ -34,14 +33,13 @@ import com.falsepattern.lib.internal.impl.config.net.SyncRequest;
import com.falsepattern.lib.internal.impl.config.net.SyncRequestHandler;
import com.falsepattern.lib.updates.ModUpdateInfo;
import com.falsepattern.lib.updates.UpdateChecker;
import lombok.val;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.Side;
import lombok.val;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;