Skip to content

Commit

Permalink
Merge pull request #12 from ZZZank/polishment
Browse files Browse the repository at this point in the history
Polishment before release
  • Loading branch information
ZZZank authored Oct 21, 2024
2 parents b92c6a8 + d327507 commit c783fd9
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 467 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ public void addBindings(BindingsEvent event) {
event.add("text", TextWrapper.class);
event.add("UUID", UUIDWrapper.class);
event.add("uuid", UUIDWrapper.class);
event.add("JsonUtils", JsonWrapper.class);
event.add("JsonIO", JsonIO.class);
event.add("JsonUtils", JsonUtilsJS.class);
event.add("JsonIO", JsonIOWrapper.class);
event.add("Block", BlockWrapper.class);
event.add("block", BlockWrapper.class);
event.add("Item", ItemWrapper.class);
Expand Down
21 changes: 4 additions & 17 deletions common/src/main/java/dev/latvian/kubejs/KubeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import dev.latvian.kubejs.util.UtilsJS;
import dev.latvian.kubejs.world.KubeJSWorldEventHandler;
import dev.latvian.kubejs.world.gen.FlatChunkGeneratorKJS;
import me.shedaniel.architectury.platform.Mod;
import lombok.val;
import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.architectury.utils.EnvExecutor;
import net.minecraft.core.Registry;
Expand Down Expand Up @@ -96,25 +96,12 @@ public KubeJS() throws Throwable {

PROXY = EnvExecutor.getEnvSpecific(() -> KubeJSClient::new, () -> KubeJSCommon::new);

long now = System.currentTimeMillis();
LOGGER.info("Looking for KubeJS plugins...");

for (Mod mod : Platform.getMods()) {
try {
for (Path path : mod.getFilePaths()) {
KubeJSPlugins.load(mod.getModId(), path);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}

LOGGER.info("Done in {} s", (System.currentTimeMillis() - now) / 1000L);
KubeJSPlugins.initFromMods();

startupScriptManager = new ScriptManager(ScriptType.STARTUP, KubeJSPaths.STARTUP_SCRIPTS, "/data/kubejs/example_startup_script.js");
clientScriptManager = new ScriptManager(ScriptType.CLIENT, KubeJSPaths.CLIENT_SCRIPTS, "/data/kubejs/example_client_script.js");

Path oldStartupFolder = KubeJSPaths.DIRECTORY.resolve("startup");
val oldStartupFolder = KubeJSPaths.DIRECTORY.resolve("startup");
if (Files.exists(oldStartupFolder)) {
UtilsJS.tryIO(() -> Files.move(oldStartupFolder, KubeJSPaths.STARTUP_SCRIPTS));
}
Expand Down Expand Up @@ -153,7 +140,7 @@ public static void loadScripts(ScriptPack pack, Path dir, String path) {
path += "/";
}

final String pathPrefix = path;
val pathPrefix = path;

UtilsJS.tryIO(() -> Files
.walk(dir, 10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
package dev.latvian.kubejs.bindings;

import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import dev.latvian.kubejs.util.JsonUtilsJS;
import dev.latvian.kubejs.util.MapJS;
import dev.latvian.mods.rhino.mod.util.JsonUtils;
import lombok.val;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;

/**
* @see dev.latvian.kubejs.util.JsonIO
* @author LatvianModder
*/
@Deprecated
public class JsonIOWrapper {

public static JsonElement readJson(String path) throws IOException {
val read = read(path);
return read == null ? JsonNull.INSTANCE : read.toJson();
}

public static String readString(String path) throws IOException {
return JsonUtils.toString(readJson(path));
}

@Nullable
public static MapJS read(File file) throws IOException {
return JsonUtilsJS.read(file);
}

public static void write(File file, Object json) throws IOException {
JsonUtilsJS.write(file, MapJS.of(json));
}

@Nullable
public static MapJS read(String file) throws IOException {
return JsonUtilsJS.read(file);
}

public static void write(File file, Object json) throws IOException {
JsonUtilsJS.write(file, MapJS.of(json));
}

public static void write(String file, Object json) throws IOException {
JsonUtilsJS.write(file, MapJS.of(json));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* @author LatvianModder
*/
@Deprecated
public class JsonWrapper {
public static JsonElement copy(JsonElement json) {
return JsonUtilsJS.copy(json);
Expand All @@ -22,6 +23,6 @@ public static String toPrettyString(JsonElement json) {
}

public static Object parse(String string) {
return UtilsJS.wrap(JsonUtilsJS.fromString(string), JSObjectType.ANY);
return UtilsJS.wrap(JsonUtilsJS.parseRaw(string), JSObjectType.ANY);
}
}
2 changes: 1 addition & 1 deletion common/src/main/java/dev/latvian/kubejs/event/EventJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected void afterPosted(boolean result) {

/**
* @param ids event ids to be used for posting events to handlers, they will be used in input order
* @return whether there's handlers called `event.cancel()` and this event itself can be cancelled
* @return true if the event itself can be cancelled and there's any handler that called `event.cancel()`, otherwise false
*/
public final boolean post(@NotNull ScriptType type, @NotNull List<String> ids) {
if (type != ScriptType.STARTUP && post(ScriptType.STARTUP, ids) && canCancel()) {
Expand Down
192 changes: 0 additions & 192 deletions common/src/main/java/dev/latvian/kubejs/util/JsonIO.java

This file was deleted.

Loading

0 comments on commit c783fd9

Please sign in to comment.