Skip to content

Commit

Permalink
try spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Jul 16, 2024
1 parent 764d560 commit fb6e6c9
Show file tree
Hide file tree
Showing 791 changed files with 14,091 additions and 14,266 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ mavenArtifactGroup = com.cleanroommc
# By default this will use the files found here: https://github.com/GregTechCEu/Buildscripts/tree/master/spotless
# to format your code. However, you can create your own version of these files and place them in your project's
# root directory to apply your own formatting options instead.
enableSpotless = false
enableSpotless = true

# Enable JUnit testing platform used for testing your code.
# Uses JUnit 5. See guide and documentation here: https://junit.org/junit5/docs/current/user-guide/
Expand Down
404 changes: 404 additions & 0 deletions spotless.eclipseformat.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.cleanroommc.groovyscript;

import java.util.Set;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.IModGuiFactory;

import java.util.Set;

public class DisabledConfigGui implements IModGuiFactory {

@Override
public void initialize(Minecraft minecraftInstance) {
}
public void initialize(Minecraft minecraftInstance) {}

@Override
public boolean hasConfigGui() {
Expand Down
128 changes: 61 additions & 67 deletions src/main/java/com/cleanroommc/groovyscript/GroovyScript.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
package com.cleanroommc.groovyscript;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.command.CustomClickAction;
import com.cleanroommc.groovyscript.command.GSCommand;
import com.cleanroommc.groovyscript.compat.content.GroovyResourcePack;
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.TinkersConstruct;
import com.cleanroommc.groovyscript.compat.vanilla.VanillaModule;
import com.cleanroommc.groovyscript.core.mixin.DefaultResourcePackAccessor;
import com.cleanroommc.groovyscript.documentation.Documentation;
import com.cleanroommc.groovyscript.documentation.linkgenerator.LinkGeneratorHooks;
import com.cleanroommc.groovyscript.event.EventHandler;
import com.cleanroommc.groovyscript.helper.JsonHelper;
import com.cleanroommc.groovyscript.mapper.ObjectMapper;
import com.cleanroommc.groovyscript.mapper.ObjectMapperManager;
import com.cleanroommc.groovyscript.network.CReload;
import com.cleanroommc.groovyscript.network.NetworkHandler;
import com.cleanroommc.groovyscript.network.NetworkUtils;
import com.cleanroommc.groovyscript.registry.ReloadableRegistryManager;
import com.cleanroommc.groovyscript.sandbox.*;
import com.cleanroommc.groovyscript.sandbox.mapper.GroovyDeobfMapper;
import com.cleanroommc.groovyscript.sandbox.security.GrSMetaClassCreationHandle;
import com.cleanroommc.groovyscript.server.GroovyScriptLanguageServer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import groovy.lang.GroovySystem;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.Random;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.settings.KeyBinding;
Expand All @@ -52,20 +35,40 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.Random;
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.command.CustomClickAction;
import com.cleanroommc.groovyscript.command.GSCommand;
import com.cleanroommc.groovyscript.compat.content.GroovyResourcePack;
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.TinkersConstruct;
import com.cleanroommc.groovyscript.compat.vanilla.VanillaModule;
import com.cleanroommc.groovyscript.core.mixin.DefaultResourcePackAccessor;
import com.cleanroommc.groovyscript.documentation.Documentation;
import com.cleanroommc.groovyscript.documentation.linkgenerator.LinkGeneratorHooks;
import com.cleanroommc.groovyscript.event.EventHandler;
import com.cleanroommc.groovyscript.helper.JsonHelper;
import com.cleanroommc.groovyscript.mapper.ObjectMapper;
import com.cleanroommc.groovyscript.mapper.ObjectMapperManager;
import com.cleanroommc.groovyscript.network.CReload;
import com.cleanroommc.groovyscript.network.NetworkHandler;
import com.cleanroommc.groovyscript.network.NetworkUtils;
import com.cleanroommc.groovyscript.registry.ReloadableRegistryManager;
import com.cleanroommc.groovyscript.sandbox.*;
import com.cleanroommc.groovyscript.sandbox.mapper.GroovyDeobfMapper;
import com.cleanroommc.groovyscript.sandbox.security.GrSMetaClassCreationHandle;
import com.cleanroommc.groovyscript.server.GroovyScriptLanguageServer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import groovy.lang.GroovySystem;

@GroovyBlacklist
@Mod(modid = GroovyScript.ID,
Expand Down Expand Up @@ -99,6 +102,8 @@ public class GroovyScript {

public static final Random RND = new Random();

public GroovyScript() {}

@Mod.EventHandler
public void onConstruction(FMLConstructionEvent event) {
MinecraftForge.EVENT_BUS.register(this);
Expand All @@ -118,7 +123,8 @@ public void onConstruction(FMLConstructionEvent event) {
if (NetworkUtils.isDedicatedClient()) {
// this resource pack must be added in construction
((DefaultResourcePackAccessor) Minecraft.getMinecraft()).get().add(new GroovyResourcePack());
reloadKey = new KeyBinding("key.groovyscript.reload", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, Keyboard.KEY_R, "key.categories.groovyscript");
reloadKey = new KeyBinding("key.groovyscript.reload", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, Keyboard.KEY_R,
"key.categories.groovyscript");
ClientRegistry.registerKeyBinding(reloadKey);
}

Expand Down Expand Up @@ -194,9 +200,8 @@ public static long runGroovyScriptsInLoader(LoadStage loadStage) {
public void onPostInit(FMLPostInitializationEvent event) {
CustomClickAction.registerAction("copy", value -> {
GuiScreen.setClipboardString(value);
Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("groovyscript.command.copy.copied_start")
.appendSibling(new TextComponentString(value).setStyle(new Style().setColor(TextFormatting.GOLD)))
.appendSibling(new TextComponentTranslation("groovyscript.command.copy.copied_end")));
Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("groovyscript.command.copy.copied_start").appendSibling(new TextComponentString(value).setStyle(new Style().setColor(TextFormatting.GOLD)))
.appendSibling(new TextComponentTranslation("groovyscript.command.copy.copied_end")));
});
}

Expand All @@ -208,64 +213,49 @@ 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 @@ -289,28 +279,32 @@ private static RunConfig createRunConfig(JsonObject json) {
if (!Files.exists(main.toPath())) {
try {
main.getParentFile().mkdirs();
Files.write(main.toPath(), "\nprintln('Hello World!')\n".getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
Files.write(main.toPath(), "\nprintln('Hello World!')\n".getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE, StandardOpenOption.WRITE);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return new RunConfig(json);
}

public static void postScriptRunResult(ICommandSender sender, boolean onlyLogFails, boolean running, boolean packmode, long time) {
public static void postScriptRunResult(ICommandSender sender, boolean onlyLogFails, boolean running, boolean packmode,
long time) {
List<String> errors = GroovyLogImpl.LOG.collectErrors();
if (errors.isEmpty()) {
if (!onlyLogFails) {
if (running) {
String s = packmode ? "changes packmode" : "reloaded scripts";
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Successfully " + s + TextFormatting.WHITE + " in " + time + "ms"));
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Successfully " + s + TextFormatting.WHITE +
" in " + time + "ms"));
} else {
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "No syntax errors found :)"));
}
}
} else {
String executing = running ? "running" : "checking";
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Found " + errors.size() + " errors while " + executing + " scripts"));
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Found " + errors.size() + " errors while " +
executing + " scripts"));
int n = errors.size();
if (errors.size() >= 10) {
sender.sendMessage(new TextComponentString("Displaying the first 7 errors:"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.cleanroommc.groovyscript;

import net.minecraftforge.common.config.Config;

import org.jetbrains.annotations.ApiStatus;

@Config(modid = GroovyScript.ID)
public class GroovyScriptConfig {

@ApiStatus.Internal
@Config.Comment("The current set packmode")
@ApiStatus.Internal @Config.Comment("The current set packmode")
public static String packmode = "";

@Config.Comment("Port for the VSC connection. Default: 25564")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
/**
* Use this annotation on fields, methods or classes to make them inaccessible for groovy.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
public @interface GroovyBlacklist {
}
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
public @interface GroovyBlacklist {}
13 changes: 7 additions & 6 deletions src/main/java/com/cleanroommc/groovyscript/api/GroovyLog.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.cleanroommc.groovyscript.api;

import com.cleanroommc.groovyscript.sandbox.GroovyLogImpl;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.cleanroommc.groovyscript.sandbox.GroovyLogImpl;

/**
* A interface for the GroovyScript logger. The log is separate to Minecraft's normal and debug log.
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/com/cleanroommc/groovyscript/api/GroovyPlugin.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.cleanroommc.groovyscript.api;

import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;

/**
* Implement this on a class to add external mod compat with GroovyScript. GroovyScript will automatically find and instantiate the class.
* Implement this on a class to add external mod compat with GroovyScript. GroovyScript will automatically find and instantiate
* the class.
* A mod should have at most one class with this interface.
*/
public interface GroovyPlugin extends IGroovyContainer {
Expand All @@ -17,29 +18,22 @@ public interface GroovyPlugin extends IGroovyContainer {
*
* @return a new mod property container
*/
@GroovyBlacklist
@ApiStatus.OverrideOnly
@GroovyBlacklist @ApiStatus.OverrideOnly
default @Nullable GroovyPropertyContainer createGroovyPropertyContainer() {
return createModPropertyContainer();
}

/**
* @deprecated use {@link #createGroovyPropertyContainer()} instead
*/
@GroovyBlacklist
@ApiStatus.OverrideOnly
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
@GroovyBlacklist @ApiStatus.OverrideOnly @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
default @Nullable ModPropertyContainer createModPropertyContainer() {
return null;
}

/**
* This method exist because of the extended interface. It has no use in this interface.
*/
@Override
@ApiStatus.NonExtendable
default boolean isLoaded() {
return true;
}
@Override @ApiStatus.NonExtendable
default boolean isLoaded() { return true; }
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.cleanroommc.groovyscript.api;

import java.util.Map;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

/**
* When this is implemented on a class, {@link #getProperty(String)} will be called when groovy tries to get a field from this class
* When this is implemented on a class, {@link #getProperty(String)} will be called when groovy tries to get a field from this
* class
*/
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0") @Deprecated
public interface IDynamicGroovyProperty {

/**
Expand Down
Loading

0 comments on commit fb6e6c9

Please sign in to comment.