Skip to content

Commit

Permalink
try 2
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Jul 16, 2024
1 parent fb6e6c9 commit f02cc82
Show file tree
Hide file tree
Showing 474 changed files with 4,022 additions and 1,575 deletions.
14 changes: 7 additions & 7 deletions spotless.eclipseformat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment" value="separate_lines_if_wrapped"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
Expand Down Expand Up @@ -59,7 +59,7 @@
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause" value="separate_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
Expand Down Expand Up @@ -102,15 +102,15 @@
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_permitted_types" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_type_annotations" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_type_annotations" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
Expand Down Expand Up @@ -198,7 +198,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_additive_operator" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case_after_arrow" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
Expand Down Expand Up @@ -226,7 +226,7 @@
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement" value="separate_lines_if_wrapped"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case" value="insert"/>
Expand All @@ -240,7 +240,7 @@
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
Expand Down
50 changes: 37 additions & 13 deletions src/main/java/com/cleanroommc/groovyscript/GroovyScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public void onConstruction(FMLConstructionEvent event) {
ReloadableRegistryManager.init();
try {
sandbox = new GroovyScriptSandbox(scriptPath, FileUtil.makeFile(FileUtil.getMinecraftHome(), "cache", "groovy"));
} catch (MalformedURLException e) {
} catch (
MalformedURLException e
) {
throw new IllegalStateException("Error initializing sandbox!");
}
ModSupport.INSTANCE.setup(event.getASMHarvestedData());
Expand Down Expand Up @@ -156,7 +158,9 @@ public static void initializeRunConfig(File minecraftHome) {
}
try {
scriptPath = scriptPath.getCanonicalFile();
} catch (IOException e) {
} catch (
IOException e
) {
GroovyLog.get().error("Failed to canonicalize groovy script path '" + scriptPath + "'!");
GroovyLog.get().exception(e);
}
Expand Down Expand Up @@ -213,49 +217,67 @@ public void onServerLoad(FMLServerStartingEvent event) {
@SubscribeEvent
public static void onInput(InputEvent.KeyInputEvent event) {
long time = Minecraft.getSystemTime();
if (Minecraft.getMinecraft().isIntegratedServerRunning() && reloadKey
.isPressed() && time - timeSinceLastUse >= 1000 && Minecraft.getMinecraft().player.getPermissionLevel() >= 4) {
if (
Minecraft.getMinecraft().isIntegratedServerRunning() && reloadKey
.isPressed() && time - timeSinceLastUse >= 1000 && Minecraft.getMinecraft().player.getPermissionLevel() >= 4
) {
NetworkHandler.sendToServer(new CReload());
timeSinceLastUse = time;
}
}

@NotNull
public static String getScriptPath() { return getScriptFile().getPath(); }
public static String getScriptPath() {
return getScriptFile().getPath();
}

@NotNull
public static File getMinecraftHome() {
if (minecraftHome == null) { throw new IllegalStateException("GroovyScript is not yet loaded!"); }
if (minecraftHome == null) {
throw new IllegalStateException("GroovyScript is not yet loaded!");
}
return minecraftHome;
}

@NotNull
public static File getScriptFile() {
if (scriptPath == null) { throw new IllegalStateException("GroovyScript is not yet loaded!"); }
if (scriptPath == null) {
throw new IllegalStateException("GroovyScript is not yet loaded!");
}
return scriptPath;
}

@NotNull
public static File getResourcesFile() {
if (resourcesFile == null) { throw new IllegalStateException("GroovyScript is not yet loaded!"); }
if (resourcesFile == null) {
throw new IllegalStateException("GroovyScript is not yet loaded!");
}
return resourcesFile;
}

@NotNull
public static File getRunConfigFile() {
if (runConfigFile == null) { throw new IllegalStateException("GroovyScript is not yet loaded!"); }
if (runConfigFile == null) {
throw new IllegalStateException("GroovyScript is not yet loaded!");
}
return runConfigFile;
}

@NotNull
public static GroovyScriptSandbox getSandbox() {
if (sandbox == null) { throw new IllegalStateException("GroovyScript is not yet loaded!"); }
if (sandbox == null) {
throw new IllegalStateException("GroovyScript is not yet loaded!");
}
return sandbox;
}

public static boolean isSandboxLoaded() { return sandbox != null; }
public static boolean isSandboxLoaded() {
return sandbox != null;
}

public static RunConfig getRunConfig() { return runConfig; }
public static RunConfig getRunConfig() {
return runConfig;
}

@ApiStatus.Internal
public static void reloadRunConfig(boolean init) {
Expand All @@ -281,7 +303,9 @@ private static RunConfig createRunConfig(JsonObject json) {
main.getParentFile().mkdirs();
Files.write(main.toPath(), "\nprintln('Hello World!')\n".getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE, StandardOpenOption.WRITE);
} catch (IOException e) {
} catch (
IOException e
) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public interface GroovyPlugin extends IGroovyContainer {
* This method exist because of the extended interface. It has no use in this interface.
*/
@Override @ApiStatus.NonExtendable
default boolean isLoaded() { return true; }
default boolean isLoaded() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ static <T> IGameObjectParser<T> wrapStringGetter(Function<String, T> getter) {

static <T> IGameObjectParser<T> wrapStringGetter(Function<String, T> getter, boolean isUpperCase) {
return (s, args) -> {
if (args.length > 0) { return Result.error("extra arguments are not allowed"); }
if (args.length > 0) {
return Result.error("extra arguments are not allowed");
}
T t = getter.apply(isUpperCase ? s.toUpperCase(Locale.ROOT) : s);
return t == null ? Result.error() : Result.some(t);
};
Expand All @@ -60,7 +62,9 @@ static <T, V> IGameObjectParser<T> wrapStringGetter(Function<String, V> getter,
static <T, V> IGameObjectParser<T> wrapStringGetter(Function<String, V> getter, Function<V, @NotNull T> trueTypeFunction,
boolean isUpperCase) {
return (s, args) -> {
if (args.length > 0) { return Result.error("extra arguments are not allowed"); }
if (args.length > 0) {
return Result.error("extra arguments are not allowed");
}
V v = getter.apply(isUpperCase ? s.toUpperCase(Locale.ROOT) : s);
return v == null ? Result.error() : Result.some(trueTypeFunction.apply(v));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public interface IGroovyContainer {
* @return aliases
*/
@NotNull
default Collection<String> getAliases() { return Collections.singletonList(getModId()); }
default Collection<String> getAliases() {
return Collections.singletonList(getModId());
}

/**
* Called before scripts are executed for the first time. Called right before
Expand All @@ -71,7 +73,9 @@ public interface IGroovyContainer {
* @see Priority
*/
@NotNull
default Priority getOverridePriority() { return Priority.NONE; }
default Priority getOverridePriority() {
return Priority.NONE;
}

enum Priority {
/**
Expand Down
37 changes: 24 additions & 13 deletions src/main/java/com/cleanroommc/groovyscript/api/IIngredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public interface IIngredient extends IResourceStack, Predicate<ItemStack> {

ItemStack[] getMatchingStacks();

default boolean isEmpty() { return getAmount() <= 0 || getMatchingStacks().length == 0; }
default boolean isEmpty() {
return getAmount() <= 0 || getMatchingStacks().length == 0;
}

default ItemStack applyTransform(ItemStack matchedInput) {
return ForgeHooks.getContainerItem(matchedInput);
Expand Down Expand Up @@ -61,17 +63,20 @@ default IIngredient withAmount(int amount) {
/**
* An empty ingredient with stack size 0, that matches empty item stacks
*/
IIngredient EMPTY = new IIngredient()
{
IIngredient EMPTY = new IIngredient() {

@Override
public int getAmount() { return 0; }
public int getAmount() {
return 0;
}

@Override
public void setAmount(int amount) {}

@Override
public boolean isEmpty() { return true; }
public boolean isEmpty() {
return true;
}

@Override
public IIngredient exactCopy() {
Expand All @@ -84,7 +89,9 @@ public Ingredient toMcIngredient() {
}

@Override
public ItemStack[] getMatchingStacks() { return new ItemStack[]{ItemStack.EMPTY}; }
public ItemStack[] getMatchingStacks() {
return new ItemStack[]{ItemStack.EMPTY};
}

@Override
public boolean test(ItemStack stack) {
Expand All @@ -95,8 +102,7 @@ public boolean test(ItemStack stack) {
/**
* An ingredient with stack size 1, that matches any item stack
*/
IIngredient ANY = new IIngredient()
{
IIngredient ANY = new IIngredient() {

@Override
public IIngredient exactCopy() {
Expand All @@ -105,8 +111,7 @@ public IIngredient exactCopy() {

@Override
public Ingredient toMcIngredient() {
return new Ingredient()
{
return new Ingredient() {

@Override
public boolean apply(@Nullable ItemStack p_apply_1_) {
Expand All @@ -116,13 +121,19 @@ public boolean apply(@Nullable ItemStack p_apply_1_) {
}

@Override
public ItemStack[] getMatchingStacks() { return new ItemStack[0]; }
public ItemStack[] getMatchingStacks() {
return new ItemStack[0];
}

@Override
public boolean isEmpty() { return false; }
public boolean isEmpty() {
return false;
}

@Override
public int getAmount() { return 1; }
public int getAmount() {
return 1;
}

@Override
public void setAmount(int amount) {}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/cleanroommc/groovyscript/api/INamed.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ public interface INamed {

default String getName() {
Collection<String> aliases = getAliases();
if (aliases.isEmpty()) { return "EmptyName"; }
if (aliases.isEmpty()) {
return "EmptyName";
}
return aliases.iterator().next();
}

@GroovyBlacklist
default boolean isEnabled() { return true; }
default boolean isEnabled() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ static <T> IObjectParser<T> wrapStringGetter(Function<String, T> getter) {

static <T> IObjectParser<T> wrapStringGetter(Function<String, T> getter, boolean isUpperCase) {
return (s, args) -> {
if (args.length > 0) { return Result.error("extra arguments are not allowed"); }
if (args.length > 0) {
return Result.error("extra arguments are not allowed");
}
T t = getter.apply(isUpperCase ? s.toUpperCase(Locale.ROOT) : s);
return t == null ? Result.error() : Result.some(t);
};
Expand All @@ -72,7 +74,9 @@ static <T, V> IObjectParser<T> wrapStringGetter(Function<String, V> getter, Func
static <T, V> IObjectParser<T> wrapStringGetter(Function<String, V> getter, Function<V, @NotNull T> trueTypeFunction,
boolean isUpperCase) {
return (s, args) -> {
if (args.length > 0) { return Result.error("extra arguments are not allowed"); }
if (args.length > 0) {
return Result.error("extra arguments are not allowed");
}
V v = getter.apply(isUpperCase ? s.toUpperCase(Locale.ROOT) : s);
return v == null ? Result.error() : Result.some(trueTypeFunction.apply(v));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ default void addFieldsOf(Object object) {
}
for (Field field : clazz.getDeclaredFields()) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (!field.isAnnotationPresent(GroovyBlacklist.class) && INamed.class.isAssignableFrom(field.getType()) && (!staticOnly || isStatic) && field.isAccessible()) {
if (
!field.isAnnotationPresent(GroovyBlacklist.class) && INamed.class.isAssignableFrom(field.getType()) && (!staticOnly || isStatic) && field.isAccessible()
) {
try {
Object o = field.get(isStatic ? null : object);
if (o != null) {
addRegistry((INamed) o);
}
} catch (IllegalAccessException e) {
} catch (
IllegalAccessException e
) {
GroovyLog.get().errorMC("Failed to register {} as virtualized registry", field.getName());
}
}
Expand Down
Loading

0 comments on commit f02cc82

Please sign in to comment.