diff --git a/src/main/java/com/troblecodings/signals/contentpacks/ChangeConfigParser.java b/src/main/java/com/troblecodings/signals/contentpacks/ChangeConfigParser.java index 840c9be78..ba8eaf1a8 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/ChangeConfigParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/ChangeConfigParser.java @@ -53,97 +53,105 @@ public static void loadChangeConfigs() { private static void loadConfigForPair(final String fileName, final String currentSignal, final String nextSignal, final Map savedPredicates, final Map> values) { - final Signal start = Signal.SIGNALS.get(currentSignal.toLowerCase()); - final Signal end = Signal.SIGNALS.get(nextSignal.toLowerCase()); - if (start == null || end == null) { - OpenSignalsMain.getLogger() - .warn("The signal '" + nextSignal + "' or the signal '" + nextSignal - + "' doen't exists! " + "This config with filename '" + fileName - + "' will be skiped!"); - return; - } - final Map.Entry pair = Maps.immutableEntry(start, end); - if (CHANGECONFIGS.containsKey(pair)) { - throw new LogicalParserException( - "A signalconfig with the signals [" + start.getSignalTypeName() + ", " - + end.getSignalTypeName() + "] does alredy exists! '" + fileName - + "' tried to register a chaneconfig for the same signalpair!"); - } - final FunctionParsingInfo startInfo = new FunctionParsingInfo(start); - final FunctionParsingInfo endInfo = new FunctionParsingInfo( - LogicParser.UNIVERSAL_TRANSLATION_TABLE, end); - final List properties = new ArrayList<>(); - - for (final Map.Entry> entry : values.entrySet()) { - - String valueToParse = entry.getKey().toLowerCase(); - Predicate, Object>> predicate = t -> true; - - if (valueToParse.contains("map(") && savedPredicates != null - && !savedPredicates.isEmpty()) { - final char[] chars = entry.getKey().toCharArray(); - String names = ""; - boolean readKey = false; - final StringBuilder builder = new StringBuilder(); - String mapKey = ""; - for (final char letter : chars) { - - final String current = builder.append(letter).toString(); - final boolean isOpenBracket = current.equals("("); - final boolean isCloseBracket = current.equals(")"); - builder.setLength(0); - - if (readKey) { - try { - if (isCloseBracket) { - valueToParse = valueToParse.replace("map(" + mapKey + ")", - "(" + savedPredicates.get(mapKey).toLowerCase() + ")"); - names = ""; - mapKey = ""; - readKey = false; + try { + + final Signal start = Signal.SIGNALS.get(currentSignal.toLowerCase()); + final Signal end = Signal.SIGNALS.get(nextSignal.toLowerCase()); + if (start == null || end == null) { + OpenSignalsMain.getLogger() + .warn("The signal '" + nextSignal + "' or the signal '" + nextSignal + + "' doen't exists! " + "This config with filename '" + fileName + + "' will be skiped!"); + return; + } + final Map.Entry pair = Maps.immutableEntry(start, end); + if (CHANGECONFIGS.containsKey(pair)) { + throw new LogicalParserException( + "A signalconfig with the signals [" + start.getSignalTypeName() + ", " + + end.getSignalTypeName() + "] does alredy exists! '" + fileName + + "' tried to register a chaneconfig for the same signalpair!"); + } + final FunctionParsingInfo startInfo = new FunctionParsingInfo(start); + final FunctionParsingInfo endInfo = new FunctionParsingInfo( + LogicParser.UNIVERSAL_TRANSLATION_TABLE, end); + final List properties = new ArrayList<>(); + + for (final Map.Entry> entry : values.entrySet()) { + + String valueToParse = entry.getKey().toLowerCase(); + Predicate, Object>> predicate = t -> true; + + if (valueToParse.contains("map(") && savedPredicates != null + && !savedPredicates.isEmpty()) { + final char[] chars = entry.getKey().toCharArray(); + String names = ""; + boolean readKey = false; + final StringBuilder builder = new StringBuilder(); + String mapKey = ""; + for (final char letter : chars) { + + final String current = builder.append(letter).toString(); + final boolean isOpenBracket = current.equals("("); + final boolean isCloseBracket = current.equals(")"); + builder.setLength(0); + + if (readKey) { + try { + if (isCloseBracket) { + valueToParse = valueToParse.replace("map(" + mapKey + ")", + "(" + savedPredicates.get(mapKey).toLowerCase() + ")"); + names = ""; + mapKey = ""; + readKey = false; + continue; + } + mapKey += current; continue; + } catch (final Exception e) { + OpenSignalsMain.exitMinecraftWithMessage( + "Something went wrong with the predicate saver in " + + fileName + "! Did you used it correctly?"); } - mapKey += current; + } + if (current.equals("(") && names.equals("map")) { + readKey = true; + mapKey = ""; continue; - } catch (final Exception e) { - OpenSignalsMain.exitMinecraftWithMessage( - "Something went wrong with the predicate saver in " + fileName - + "! Did you used it correctly?"); } + final boolean isBracket = isCloseBracket || isOpenBracket; + if (Character.isWhitespace(letter) || current.equals("!") || isBracket) { + names = ""; + mapKey = ""; + continue; + } + names += current; } - if (current.equals("(") && names.equals("map")) { - readKey = true; - mapKey = ""; - continue; - } - final boolean isBracket = isCloseBracket || isOpenBracket; - if (Character.isWhitespace(letter) || current.equals("!") || isBracket) { - names = ""; - mapKey = ""; - continue; - } - names += current; } - } - if (valueToParse != null && !valueToParse.isEmpty() - && !valueToParse.equalsIgnoreCase("true")) { - predicate = LogicParser.predicate(valueToParse, endInfo); - } + if (valueToParse != null && !valueToParse.isEmpty() + && !valueToParse.equalsIgnoreCase("true")) { + predicate = LogicParser.predicate(valueToParse, endInfo); + } - final Map propertiesToSet = new HashMap<>(); + final Map propertiesToSet = new HashMap<>(); - for (final String value : entry.getValue()) { + for (final String value : entry.getValue()) { - final String[] valuetoChange = value.split("\\."); - final SEProperty property = (SEProperty) startInfo.getProperty(valuetoChange[0]); - propertiesToSet.put(property, valuetoChange[1]); - } + final String[] valuetoChange = value.split("\\."); + final SEProperty property = (SEProperty) startInfo + .getProperty(valuetoChange[0]); + propertiesToSet.put(property, valuetoChange[1]); + } - properties.add(new ConfigProperty(predicate, propertiesToSet)); + properties.add(new ConfigProperty(predicate, propertiesToSet)); + } + CHANGECONFIGS.put(pair, properties); + } catch (final Exception e) { + OpenSignalsMain.getLogger().error("There was a problem loading the ChangeConfig [" + + fileName + "]! Please check the file!"); + e.printStackTrace(); } - CHANGECONFIGS.put(pair, properties); } private static class ChangeConfigParserV2 { diff --git a/src/main/java/com/troblecodings/signals/contentpacks/OneSignalNonPredicateConfigParser.java b/src/main/java/com/troblecodings/signals/contentpacks/OneSignalNonPredicateConfigParser.java index 94f0ada7e..070794509 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/OneSignalNonPredicateConfigParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/OneSignalNonPredicateConfigParser.java @@ -59,38 +59,45 @@ public static void loadOneSignalNonPredicateConfig(final Map> map, - final String fileName, final String currentSignal, final List values) { - final Signal signal = checkSignal(currentSignal, fileName); - if (signal == null) - return; - - if (map.containsKey(signal)) { - throw new LogicalParserException("A signalconfig with the signals [" - + signal.getSignalTypeName() + "] does alredy exists! '" + fileName - + "' tried to register the same signalconfig!"); - } + final String fileName, final String currentSignal, final List values, + final String path) { + try { + final Signal signal = checkSignal(currentSignal, fileName); + if (signal == null) + return; + + if (map.containsKey(signal)) { + throw new LogicalParserException("A signalconfig with the signals [" + + signal.getSignalTypeName() + "] does alredy exists! '" + fileName + + "' tried to register the same signalconfig!"); + } - final FunctionParsingInfo info = new FunctionParsingInfo(signal); - final List propertes = new ArrayList<>(); - for (final String property : values) { - final String[] value = property.split("\\."); - propertes.add(new ConfigProperty(t -> true, - ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1]))); + final FunctionParsingInfo info = new FunctionParsingInfo(signal); + final List propertes = new ArrayList<>(); + for (final String property : values) { + final String[] value = property.split("\\."); + propertes.add(new ConfigProperty(t -> true, + ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1]))); + } + map.put(signal, propertes); + } catch (final Exception e) { + OpenSignalsMain.getLogger().error("There was a problem loading the config [" + fileName + + "] located in [" + path + "]! Please check the file!"); + e.printStackTrace(); } - map.put(signal, propertes); } private static Signal checkSignal(final String signalName, final String filename) { diff --git a/src/main/java/com/troblecodings/signals/contentpacks/OneSignalPredicateConfigParser.java b/src/main/java/com/troblecodings/signals/contentpacks/OneSignalPredicateConfigParser.java index b977c0925..35fcce73c 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/OneSignalPredicateConfigParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/OneSignalPredicateConfigParser.java @@ -47,7 +47,7 @@ public static void loadOneSignalPredicateConfigEntry( OneSignalPredicateConfigParserV2.class); for (final String currentSignal : parser.currentSignals) { loadConfig(map, files.getKey(), currentSignal, parser.savedPredicates, - parser.values); + parser.values, path); } } catch (final Exception e) { OpenSignalsMain.getLogger().error("Please update your config [" + files.getKey() @@ -55,99 +55,108 @@ public static void loadOneSignalPredicateConfigEntry( final OneSignalPredicateConfigParser parser = GSON.fromJson(files.getValue(), OneSignalPredicateConfigParser.class); loadConfig(map, files.getKey(), parser.currentSignal, parser.savedPredicates, - parser.values); + parser.values, path); } } private static void loadConfig(final Map> map, final String fileName, final String currentSignal, - final Map savedPredicates, final Map> values) { - final Signal signal = Signal.SIGNALS.get(currentSignal.toLowerCase()); - if (signal == null) { - OpenSignalsMain.getLogger().warn("The signal '" + currentSignal + "' doesn't exists! " - + "This config with the filename '" + fileName + "' will be skiped!"); - return; - } - if (map.containsKey(signal)) { - throw new LogicalParserException("A signalconfig with the signals [" - + signal.getSignalTypeName() + "] does alredy exists! '" + fileName - + "' tried to register a defaultconfig for the same signal!"); - } - final FunctionParsingInfo info = new FunctionParsingInfo( - LogicParser.UNIVERSAL_TRANSLATION_TABLE, signal); - final List properties = new ArrayList<>(); - - for (final Map.Entry> entry : values.entrySet()) { - - String valueToParse = entry.getKey().toLowerCase(); - Predicate, Object>> predicate = t -> true; - - if (valueToParse.contains("map(") && savedPredicates != null - && !savedPredicates.isEmpty()) { - final char[] chars = entry.getKey().toCharArray(); - String names = ""; - boolean readKey = false; - final StringBuilder builder = new StringBuilder(); - String mapKey = ""; - for (final char letter : chars) { - - final String current = builder.append(letter).toString(); - final boolean isOpenBracket = current.equals("("); - final boolean isCloseBracket = current.equals(")"); - builder.setLength(0); - - if (readKey) { - try { - if (isCloseBracket) { - valueToParse = valueToParse.replace("map(" + mapKey + ")", - "(" + savedPredicates.get(mapKey).toLowerCase() + ")"); - names = ""; - mapKey = ""; - readKey = false; + final Map savedPredicates, final Map> values, + final String path) { + try { + final Signal signal = Signal.SIGNALS.get(currentSignal.toLowerCase()); + if (signal == null) { + OpenSignalsMain.getLogger() + .warn("The signal '" + currentSignal + "' doesn't exists! " + + "This config with the filename '" + fileName + + "' will be skiped!"); + return; + } + if (map.containsKey(signal)) { + throw new LogicalParserException("A signalconfig with the signals [" + + signal.getSignalTypeName() + "] does alredy exists! '" + fileName + + "' tried to register a defaultconfig for the same signal!"); + } + final FunctionParsingInfo info = new FunctionParsingInfo( + LogicParser.UNIVERSAL_TRANSLATION_TABLE, signal); + final List properties = new ArrayList<>(); + + for (final Map.Entry> entry : values.entrySet()) { + + String valueToParse = entry.getKey().toLowerCase(); + Predicate, Object>> predicate = t -> true; + + if (valueToParse.contains("map(") && savedPredicates != null + && !savedPredicates.isEmpty()) { + final char[] chars = entry.getKey().toCharArray(); + String names = ""; + boolean readKey = false; + final StringBuilder builder = new StringBuilder(); + String mapKey = ""; + for (final char letter : chars) { + + final String current = builder.append(letter).toString(); + final boolean isOpenBracket = current.equals("("); + final boolean isCloseBracket = current.equals(")"); + builder.setLength(0); + + if (readKey) { + try { + if (isCloseBracket) { + valueToParse = valueToParse.replace("map(" + mapKey + ")", + "(" + savedPredicates.get(mapKey).toLowerCase() + ")"); + names = ""; + mapKey = ""; + readKey = false; + continue; + } + mapKey += current; continue; + } catch (final Exception e) { + OpenSignalsMain.exitMinecraftWithMessage( + "Something went wrong with the predicate saver in " + + fileName + "! Did you used it correctly?"); } - mapKey += current; + } + if (current.equals("(") && names.equals("map")) { + readKey = true; + mapKey = ""; continue; - } catch (final Exception e) { - OpenSignalsMain.exitMinecraftWithMessage( - "Something went wrong with the predicate saver in " + fileName - + "! Did you used it correctly?"); } + final boolean isBracket = isCloseBracket || isOpenBracket; + if (Character.isWhitespace(letter) || current.equals("!") || isBracket) { + names = ""; + mapKey = ""; + continue; + } + names += current; } - if (current.equals("(") && names.equals("map")) { - readKey = true; - mapKey = ""; - continue; - } - final boolean isBracket = isCloseBracket || isOpenBracket; - if (Character.isWhitespace(letter) || current.equals("!") || isBracket) { - names = ""; - mapKey = ""; - continue; - } - names += current; } - } - if (valueToParse != null && !valueToParse.isEmpty() - && !valueToParse.equalsIgnoreCase("true")) { - predicate = LogicParser.predicate(valueToParse, info); - } + if (valueToParse != null && !valueToParse.isEmpty() + && !valueToParse.equalsIgnoreCase("true")) { + predicate = LogicParser.predicate(valueToParse, info); + } - final Map propertiesToSet = new HashMap<>(); + final Map propertiesToSet = new HashMap<>(); - for (final String value : entry.getValue()) { + for (final String value : entry.getValue()) { - final String[] valuetoChange = value.split("\\."); - final SEProperty property = (SEProperty) info.getProperty(valuetoChange[0]); - propertiesToSet.put(property, valuetoChange[1]); - } + final String[] valuetoChange = value.split("\\."); + final SEProperty property = (SEProperty) info.getProperty(valuetoChange[0]); + propertiesToSet.put(property, valuetoChange[1]); + } - properties.add(new ConfigProperty(predicate, propertiesToSet)); + properties.add(new ConfigProperty(predicate, propertiesToSet)); + } + map.put(signal, properties); + } catch (final Exception e) { + OpenSignalsMain.getLogger().error("There was a problem loading the config [" + fileName + + "] located in [" + path + "]! Please check the file!"); + e.printStackTrace(); } - map.put(signal, properties); } private static class OneSignalPredicateConfigParserV2 { diff --git a/src/main/java/com/troblecodings/signals/contentpacks/SubsidiarySignalParser.java b/src/main/java/com/troblecodings/signals/contentpacks/SubsidiarySignalParser.java index 48c01d1f8..0535ea408 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/SubsidiarySignalParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/SubsidiarySignalParser.java @@ -40,20 +40,27 @@ private static void loadSubsidiaryStates() { public static void loadAllSubsidiarySignals() { loadSubsidiaryStates(); OpenSignalsMain.contentPacks.getFiles("signalconfigs/subsidiary").forEach(entry -> { - final SubsidiarySignalParser parser = GSON.fromJson(entry.getValue(), - SubsidiarySignalParser.class); - final Signal signal = Signal.SIGNALS.get(parser.currentSignal.toLowerCase()); - if (signal == null) - OpenSignalsMain.exitMinecraftWithMessage( - "There doesn't exists a signal with the name '" + parser.currentSignal - + "'! Valid Signals are: " + Signal.SIGNALS.keySet()); - if (SUBSIDIARY_SIGNALS.containsKey(signal)) - OpenSignalsMain.exitMinecraftWithMessage( - "There already exists a Subsidiary Config for " + signal + "!"); - final FunctionParsingInfo info = new FunctionParsingInfo(signal); - parser.allStates.forEach((name, properties) -> { - convertToProperites(signal, info, properties, name); - }); + try { + final SubsidiarySignalParser parser = GSON.fromJson(entry.getValue(), + SubsidiarySignalParser.class); + final Signal signal = Signal.SIGNALS.get(parser.currentSignal.toLowerCase()); + if (signal == null) + OpenSignalsMain.exitMinecraftWithMessage( + "There doesn't exists a signal with the name '" + parser.currentSignal + + "'! Valid Signals are: " + Signal.SIGNALS.keySet()); + if (SUBSIDIARY_SIGNALS.containsKey(signal)) + OpenSignalsMain.exitMinecraftWithMessage( + "There already exists a Subsidiary Config for " + signal + "!"); + final FunctionParsingInfo info = new FunctionParsingInfo(signal); + parser.allStates.forEach((name, properties) -> { + convertToProperites(signal, info, properties, name); + }); + } catch (final Exception e) { + OpenSignalsMain.getLogger().error("There was a problem loading the config [" + + entry.getKey() + + "] located in [signalconfigs/subsidiary]! Please check the file!"); + e.printStackTrace(); + } }); }