[root] Initial 1.19 support, not yet ready

This commit is contained in:
Johannes Frohnmeyer 2022-06-03 22:45:14 +02:00
parent e8a3257b3c
commit f916c68c00
Signed by: Johannes
GPG Key ID: E76429612C2929F4
35 changed files with 102 additions and 726 deletions

View File

@ -19,9 +19,8 @@ allprojects {
}
dependencies {
modImplementation("com.terraformersmc:modmenu:3.1.0")
modImplementation("com.terraformersmc:modmenu:4.0.0-beta.4")
modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:$project.fabric_version")
//TODO update for 1.19
implementation("io.gitlab.jfronny:commons:$project.commons_version")
implementation("io.gitlab.jfronny:commons-gson:$project.commons_version")
implementation("io.gitlab.jfronny:commons-slf4j:$rootProject.commons_version")

View File

@ -1,8 +1,8 @@
# https://fabricmc.net/develop/
minecraft_version=1.18.2
yarn_mappings=build.3
loader_version=0.14.5
fabric_version=0.51.1+1.18.2
minecraft_version=1.19-rc2
yarn_mappings=build.1
loader_version=0.14.6
fabric_version=0.55.0+1.19
maven_group=io.gitlab.jfronny.libjf
archive_base_name=libjf
@ -13,4 +13,4 @@ modrinth_optional_dependencies=P7dR8mSH
curseforge_id=482600
curseforge_optional_dependencies=fabric-api
commons_version=2022.5.10+15-34-20
commons_version=2022.6.3+18-31-48

View File

@ -1,5 +1,7 @@
package io.gitlab.jfronny.libjf;
import io.gitlab.jfronny.commons.serialize.gson.api.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -84,7 +86,7 @@ public class HttpUtils {
public Request bodyJson(Object object) {
builder.header("Content-Type", "application/json");
builder.method(method.name(), HttpRequest.BodyPublishers.ofString(LibJf.GSON.toJson(object)));
builder.method(method.name(), HttpRequest.BodyPublishers.ofString(GsonHolder.getGson().toJson(object)));
method = null;
return this;
@ -142,7 +144,7 @@ public class HttpUtils {
public <T> T sendJson(Type type) throws IOException {
InputStream in = _send("application/json", HttpResponse.BodyHandlers.ofInputStream());
return in == null ? null : LibJf.GSON.fromJson(new InputStreamReader(in), type);
return in == null ? null : GsonHolder.getGson().fromJson(new InputStreamReader(in), type);
}
private String getString(Object a) throws IOException {

View File

@ -1,33 +1,24 @@
package io.gitlab.jfronny.libjf;
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
import io.gitlab.jfronny.gson.Gson;
import io.gitlab.jfronny.gson.GsonBuilder;
import io.gitlab.jfronny.libjf.gson.GsonAdapter;
import io.gitlab.jfronny.libjf.gson.HiddenAnnotationExclusionStrategy;
import net.fabricmc.loader.api.FabricLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.gitlab.jfronny.commons.log.*;
import io.gitlab.jfronny.commons.serialize.gson.api.*;
import io.gitlab.jfronny.gson.*;
import io.gitlab.jfronny.libjf.gson.*;
import net.fabricmc.loader.api.*;
public class LibJf {
private LibJf() {
}
public static final String MOD_ID = "libjf";
@Deprecated(forRemoval = true) // This should be a jf java-commons logger
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Deprecated(forRemoval = true)
public static final Gson GSON;
public static final Logger LOGGER = Logger.forName(MOD_ID);
static {
GsonHolder.modifyBuilder((final GsonBuilder builder) -> {
for (GsonAdapter adapter : FabricLoader.getInstance().getEntrypoints(MOD_ID + ":gson_adapter", GsonAdapter.class)) {
if (adapter.apply(builder) != builder) {
LOGGER.warn("gson_adapter attempted to replace GsonBuilder. This is no longer supported");
}
adapter.apply(builder);
}
});
HiddenAnnotationExclusionStrategy.register();
GSON = GsonHolder.getGson();
GsonHolder.register();
}
}

View File

@ -1,31 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
import java.util.function.Supplier;
@Deprecated(forRemoval = true)
public class LazySupplier<T> implements Supplier<T> {
private final Supplier<T> supplier;
private T cache = null;
public LazySupplier(@NotNull T value) {
this.supplier = () -> {
throw new RuntimeException("Supplier should have never been called");
};
cache = value;
}
public LazySupplier(@NotNull Supplier<T> supplier) {
this.supplier = supplier;
}
@Override @Contract(pure = true) @NotNull public T get() {
if (cache == null) cache = supplier.get();
return cache;
}
@Contract(pure = true) @NotNull public LazySupplier<T> andThen(@NotNull Function<LazySupplier<T>, T> after) {
return new LazySupplier<>(() -> after.apply(this));
}
}

View File

@ -1,70 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
@Deprecated(forRemoval = true)
@FunctionalInterface
public interface ThrowingBiConsumer<T, U, TEx extends Throwable> {
void accept(T var1, U var2) throws TEx;
default <V> ThrowingConsumer<V, TEx> compose(ThrowingFunction<? super V, ? extends T, ? extends TEx> left, ThrowingFunction<? super V, ? extends U, ? extends TEx> right) {
Objects.requireNonNull(left);
Objects.requireNonNull(right);
return (t) -> this.accept(left.apply(t), right.apply(t));
}
default <V, W> ThrowingBiConsumer<V, W, TEx> biCompose(ThrowingFunction<? super V, ? extends T, ? extends TEx> left, ThrowingFunction<? super W, ? extends U, ? extends TEx> right) {
Objects.requireNonNull(left);
Objects.requireNonNull(right);
return (l, r) -> this.accept(left.apply(l), right.apply(r));
}
default <V> ThrowingBiConsumer<V, U, TEx> composeLeft(ThrowingFunction<? super V, ? extends T, ? extends TEx> before) {
Objects.requireNonNull(before);
return (l, r) -> this.accept(before.apply(l), r);
}
default <V> ThrowingBiConsumer<T, V, TEx> composeRight(ThrowingFunction<? super V, ? extends U, ? extends TEx> before) {
Objects.requireNonNull(before);
return (l, r) -> this.accept(l, before.apply(r));
}
default ThrowingBiConsumer<T, U, TEx> andThen(ThrowingBiConsumer<? super T, ? super U, ? extends TEx> after) {
Objects.requireNonNull(after);
return (l, r) -> {
this.accept(l, r);
after.accept(l, r);
};
}
default ThrowingBiConsumer<T, U, TEx> andThen(ThrowingRunnable<? extends TEx> after) {
Objects.requireNonNull(after);
return (l, r) -> {
this.accept(l, r);
after.run();
};
}
default BiConsumer<T, U> addHandler(Consumer<Throwable> handler) {
Objects.requireNonNull(handler);
return (l, r) -> {
try {
this.accept(l, r);
} catch (Throwable e) {
handler.accept(e);
}
};
}
default BiConsumer<T, U> orThrow() {
return (l, r) -> {
try {
this.accept(l, r);
} catch (Throwable e) {
throw Try.runtimeException(e);
}
};
}
}

View File

@ -1,64 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
@Deprecated(forRemoval = true)
@FunctionalInterface
public interface ThrowingBiFunction<T, U, R, TEx extends Throwable> {
R apply(T var1, U var2) throws TEx;
default <V> ThrowingFunction<V, R, TEx> compose(ThrowingFunction<? super V, ? extends T, ? extends TEx> left, ThrowingFunction<? super V, ? extends U, ? extends TEx> right) {
Objects.requireNonNull(left);
Objects.requireNonNull(right);
return (t) -> this.apply(left.apply(t), right.apply(t));
}
default <V, W> ThrowingBiFunction<V, W, R, TEx> biCompose(ThrowingFunction<? super V, ? extends T, ? extends TEx> left, ThrowingFunction<? super W, ? extends U, ? extends TEx> right) {
Objects.requireNonNull(left);
Objects.requireNonNull(right);
return (l, r) -> this.apply(left.apply(l), right.apply(r));
}
default <V> ThrowingBiFunction<V, U, R, TEx> composeLeft(ThrowingFunction<? super V, ? extends T, ? extends TEx> before) {
Objects.requireNonNull(before);
return (l, r) -> this.apply(before.apply(l), r);
}
default <V> ThrowingBiFunction<T, V, R, TEx> composeRight(ThrowingFunction<? super V, ? extends U, ? extends TEx> before) {
Objects.requireNonNull(before);
return (l, r) -> this.apply(l, before.apply(r));
}
default <V> ThrowingBiFunction<T, U, V, TEx> andThen(ThrowingFunction<? super R, ? extends V, ? extends TEx> after) {
Objects.requireNonNull(after);
return (t, u) -> after.apply(this.apply(t, u));
}
default ThrowingBiConsumer<T, U, TEx> andThen(ThrowingConsumer<? super R, ? extends TEx> after) {
Objects.requireNonNull(after);
return (t, u) -> after.accept(this.apply(t, u));
}
default BiFunction<T, U, R> addHandler(Function<Throwable, ? extends R> handler) {
Objects.requireNonNull(handler);
return (t, u) -> {
try {
return this.apply(t, u);
} catch (Throwable e) {
return handler.apply(e);
}
};
}
default BiFunction<T, U, R> orThrow() {
return (t, u) -> {
try {
return this.apply(t, u);
} catch (Throwable e) {
throw Try.runtimeException(e);
}
};
}
}

View File

@ -1,70 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;
@Deprecated(forRemoval = true)
@FunctionalInterface
public interface ThrowingBooleanSupplier<TEx extends Throwable> {
boolean get() throws TEx;
default <T> ThrowingPredicate<T, TEx> and(ThrowingPredicate<? super T, ? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.get() && other.test(t);
}
default ThrowingBooleanSupplier<TEx> and(ThrowingBooleanSupplier<? extends TEx> other) {
Objects.requireNonNull(other);
return () -> this.get() && other.get();
}
default <T> ThrowingPredicate<T, TEx> or(ThrowingPredicate<? super T, ? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.get() || other.test(t);
}
default ThrowingBooleanSupplier<TEx> or(ThrowingBooleanSupplier<? extends TEx> other) {
Objects.requireNonNull(other);
return () -> this.get() || other.get();
}
default <T> ThrowingPredicate<T, TEx> xor(ThrowingPredicate<? super T, ? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.get() ^ other.test(t);
}
default ThrowingBooleanSupplier<TEx> xor(ThrowingBooleanSupplier<? extends TEx> other) {
Objects.requireNonNull(other);
return () -> this.get() ^ other.get();
}
default ThrowingBooleanSupplier<TEx> negate() {
return () -> !this.get();
}
static <TEx extends Throwable> ThrowingBooleanSupplier<TEx> not(ThrowingBooleanSupplier<TEx> target) {
return Objects.requireNonNull(target).negate();
}
default BooleanSupplier addHandler(Predicate<Throwable> handler) {
Objects.requireNonNull(handler);
return () -> {
try {
return this.get();
} catch (Throwable e) {
return handler.test(e);
}
};
}
default BooleanSupplier orThrow() {
return () -> {
try {
return this.get();
} catch (Throwable e) {
throw Try.runtimeException(e);
}
};
}
}

View File

@ -1,65 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.Consumer;
@Deprecated(forRemoval = true)
@FunctionalInterface
public interface ThrowingConsumer<T, TEx extends Throwable> {
void accept(T var1) throws TEx;
default <V> ThrowingConsumer<V, TEx> compose(ThrowingFunction<? super V, ? extends T, ? extends TEx> before) {
Objects.requireNonNull(before);
return (t) -> this.accept(before.apply(t));
}
default ThrowingRunnable<TEx> compose(ThrowingSupplier<? extends T, ? extends TEx> before) {
Objects.requireNonNull(before);
return () -> this.accept(before.get());
}
default ThrowingConsumer<T, TEx> andThen(ThrowingConsumer<? super T, ? extends TEx> after) {
Objects.requireNonNull(after);
return (t) -> {
this.accept(t);
after.accept(t);
};
}
default ThrowingConsumer<T, TEx> andThen(ThrowingRunnable<? extends TEx> after) {
Objects.requireNonNull(after);
return (t) -> {
this.accept(t);
after.run();
};
}
default <V> ThrowingBiConsumer<T, V, TEx> compound(ThrowingConsumer<? super V, ? extends TEx> other) {
Objects.requireNonNull(other);
return (l, r) -> {
this.accept(l);
other.accept(r);
};
}
default Consumer<T> addHandler(Consumer<Throwable> handler) {
Objects.requireNonNull(handler);
return (t) -> {
try {
this.accept(t);
} catch (Throwable e) {
handler.accept(e);
}
};
}
default Consumer<T> orThrow() {
return (t) -> {
try {
this.accept(t);
} catch (Throwable e) {
throw Try.runtimeException(e);
}
};
}
}

View File

@ -1,56 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.Function;
@Deprecated(forRemoval = true)
@FunctionalInterface
public interface ThrowingFunction<T, R, TEx extends Throwable> {
R apply(T var1) throws TEx;
default ThrowingSupplier<R, TEx> compose(ThrowingSupplier<? extends T, ? extends TEx> before) {
Objects.requireNonNull(before);
return () -> this.apply(before.get());
}
default <V> ThrowingFunction<V, R, TEx> compose(ThrowingFunction<? super V, ? extends T, ? extends TEx> before) {
Objects.requireNonNull(before);
return (v) -> this.apply(before.apply(v));
}
default <V> ThrowingFunction<T, V, TEx> andThen(ThrowingFunction<? super R, ? extends V, ? extends TEx> after) {
Objects.requireNonNull(after);
return (t) -> after.apply(this.apply(t));
}
default ThrowingPredicate<T, TEx> andThen(ThrowingPredicate<? super R, ? extends TEx> after) {
Objects.requireNonNull(after);
return (t) -> after.test(this.apply(t));
}
default ThrowingConsumer<T, TEx> andThen(ThrowingConsumer<? super R, ? extends TEx> after) {
Objects.requireNonNull(after);
return (t) -> after.accept(this.apply(t));
}
default Function<T, R> addHandler(Function<Throwable, ? extends R> handler) {
Objects.requireNonNull(handler);
return (t) -> {
try {
return this.apply(t);
} catch (Throwable e) {
return handler.apply(e);
}
};
}
default Function<T, R> orThrow() {
return (t) -> {
try {
return this.apply(t);
} catch (Throwable e) {
throw Try.runtimeException(e);
}
};
}
}

View File

@ -1,83 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.Predicate;
@Deprecated(forRemoval = true)
@FunctionalInterface
public interface ThrowingPredicate<T, TEx extends Throwable> {
boolean test(T var1) throws TEx;
default <V> ThrowingPredicate<V, TEx> compose(ThrowingFunction<? super V, ? extends T, ? extends TEx> before) {
Objects.requireNonNull(before);
return (t) -> this.test(before.apply(t));
}
default ThrowingBooleanSupplier<TEx> compose(ThrowingSupplier<? extends T, ? extends TEx> before) {
Objects.requireNonNull(before);
return () -> this.test(before.get());
}
default ThrowingPredicate<T, TEx> and(ThrowingPredicate<? super T, ? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.test(t) && other.test(t);
}
default ThrowingPredicate<T, TEx> and(ThrowingBooleanSupplier<? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.test(t) && other.get();
}
default ThrowingPredicate<T, TEx> or(ThrowingPredicate<? super T, ? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.test(t) || other.test(t);
}
default ThrowingPredicate<T, TEx> or(ThrowingBooleanSupplier<? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.test(t) || other.get();
}
default ThrowingPredicate<T, TEx> xor(ThrowingPredicate<? super T, ? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.test(t) ^ other.test(t);
}
default ThrowingPredicate<T, TEx> xor(ThrowingBooleanSupplier<? extends TEx> other) {
Objects.requireNonNull(other);
return (t) -> this.test(t) ^ other.get();
}
default ThrowingPredicate<T, TEx> negate() {
return (t) -> !this.test(t);
}
static <T> ThrowingPredicate<T, Throwable> isEqual(Object targetRef) {
return null == targetRef ? Objects::isNull : targetRef::equals;
}
static <T, TEx extends Throwable> ThrowingPredicate<T, TEx> not(ThrowingPredicate<T, TEx> target) {
return Objects.requireNonNull(target).negate();
}
default Predicate<T> addHandler(Predicate<Throwable> handler) {
Objects.requireNonNull(handler);
return (r) -> {
try {
return this.test(r);
} catch (Throwable e) {
return handler.test(e);
}
};
}
default Predicate<T> orThrow() {
return (r) -> {
try {
return this.test(r);
} catch (Throwable e) {
throw Try.runtimeException(e);
}
};
}
}

View File

@ -1,47 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.Consumer;
@Deprecated(forRemoval = true)
@FunctionalInterface
public interface ThrowingRunnable<TEx extends Throwable> {
void run() throws TEx;
default ThrowingRunnable<TEx> compose(ThrowingRunnable<? extends TEx> before) {
Objects.requireNonNull(before);
return () -> {
before.run();
this.run();
};
}
default ThrowingRunnable<TEx> andThen(ThrowingRunnable<? extends TEx> after) {
Objects.requireNonNull(after);
return () -> {
this.run();
after.run();
};
}
default Runnable addHandler(Consumer<Throwable> handler) {
Objects.requireNonNull(handler);
return () -> {
try {
this.run();
} catch (Throwable e) {
handler.accept(e);
}
};
}
default Runnable orThrow() {
return () -> {
try {
this.run();
} catch (Throwable e) {
throw Try.runtimeException(e);
}
};
}
}

View File

@ -1,47 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
@Deprecated(forRemoval = true)
@FunctionalInterface
public interface ThrowingSupplier<T, TEx extends Throwable> {
T get() throws TEx;
default <V> ThrowingSupplier<V, TEx> andThen(ThrowingFunction<? super T, ? extends V, ? extends TEx> after) {
Objects.requireNonNull(after);
return () -> after.apply(this.get());
}
default ThrowingBooleanSupplier<TEx> andThen(ThrowingPredicate<? super T, ? extends TEx> after) {
Objects.requireNonNull(after);
return () -> after.test(this.get());
}
default ThrowingRunnable<TEx> andThen(ThrowingConsumer<? super T, ? extends TEx> after) {
Objects.requireNonNull(after);
return () -> after.accept(this.get());
}
default Supplier<T> addHandler(Function<Throwable, ? extends T> handler) {
Objects.requireNonNull(handler);
return () -> {
try {
return this.get();
} catch (Throwable e) {
return handler.apply(e);
}
};
}
default Supplier<T> orThrow() {
return () -> {
try {
return this.get();
} catch (Throwable e) {
throw Try.runtimeException(e);
}
};
}
}

View File

@ -1,59 +0,0 @@
package io.gitlab.jfronny.libjf.generic;
import java.util.Objects;
import java.util.function.*;
@Deprecated(forRemoval = true)
public class Try {
public static void orElse(ThrowingRunnable<?> tr, Consumer<Throwable> alternative) {
Objects.requireNonNull(tr).addHandler(alternative).run();
}
public static <T> T orElse(ThrowingSupplier<T, ?> tr, Function<Throwable, ? extends T> alternative) {
return Objects.requireNonNull(tr).addHandler(alternative).get();
}
public static void orThrow(ThrowingRunnable<?> tr) {
Objects.requireNonNull(tr).orThrow().run();
}
public static <T> T orThrow(ThrowingSupplier<T, ?> tr) {
return Objects.requireNonNull(tr).orThrow().get();
}
public static <T, U> BiConsumer<T, U> handle(ThrowingBiConsumer<T, U, ?> tr, Consumer<Throwable> handler) {
return Objects.requireNonNull(tr).addHandler(handler);
}
public static <T, U, R> BiFunction<T, U, R> handle(ThrowingBiFunction<T, U, R, ?> tr, Function<Throwable, ? extends R> handler) {
return Objects.requireNonNull(tr).addHandler(handler);
}
public static BooleanSupplier handle(ThrowingBooleanSupplier<?> tr, Predicate<Throwable> handler) {
return Objects.requireNonNull(tr).addHandler(handler);
}
public static <T> Consumer<T> handle(ThrowingConsumer<T, ?> tr, Consumer<Throwable> handler) {
return Objects.requireNonNull(tr).addHandler(handler);
}
public static <T, R> Function<T, R> handle(ThrowingFunction<T, R, ?> tr, Function<Throwable, ? extends R> handler) {
return Objects.requireNonNull(tr).addHandler(handler);
}
public static <T> Predicate<T> handle(ThrowingPredicate<T, ?> tr, Predicate<Throwable> handler) {
return Objects.requireNonNull(tr).addHandler(handler);
}
public static Runnable handle(ThrowingRunnable<?> tr, Consumer<Throwable> handler) {
return Objects.requireNonNull(tr).addHandler(handler);
}
public static <T> Supplier<T> handle(ThrowingSupplier<T, ?> tr, Function<Throwable, ? extends T> handler) {
return Objects.requireNonNull(tr).addHandler(handler);
}
protected static RuntimeException runtimeException(Throwable t) {
return t == null ? null : t instanceof RuntimeException e ? e : new RuntimeException(t);
}
}

View File

@ -3,5 +3,5 @@ package io.gitlab.jfronny.libjf.gson;
import io.gitlab.jfronny.gson.GsonBuilder;
public interface GsonAdapter {
GsonBuilder apply(GsonBuilder builder);
void apply(GsonBuilder builder);
}

View File

@ -1,12 +0,0 @@
package io.gitlab.jfronny.libjf.gson;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Deprecated(forRemoval = true)
public @interface GsonHidden {
}

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.libjf.gson;
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
import io.gitlab.jfronny.commons.serialize.gson.api.GsonHolder;
import io.gitlab.jfronny.gson.ExclusionStrategy;
import io.gitlab.jfronny.gson.FieldAttributes;
import net.fabricmc.api.EnvType;
@ -11,7 +11,6 @@ public class HiddenAnnotationExclusionStrategy implements ExclusionStrategy {
return false;
}
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
if (fieldAttributes.getAnnotation(GsonHidden.class) != null) return true;
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT
? fieldAttributes.getAnnotation(ServerOnly.class) != null
: fieldAttributes.getAnnotation(ClientOnly.class) != null;

View File

@ -3,5 +3,5 @@ archivesBaseName = "libjf-config-v0"
dependencies {
moduleDependencies(project, ["libjf-base", "libjf-unsafe-v0"])
include(fabricApi.module("fabric-resource-loader-v0", "${project.fabric_version}"))
include modImplementation(fabricApi.module("fabric-command-api-v1", "${project.fabric_version}"))
include modImplementation(fabricApi.module("fabric-command-api-v2", "${project.fabric_version}"))
}

View File

@ -1,25 +1,16 @@
package io.gitlab.jfronny.libjf.config.impl;
import com.google.common.collect.ImmutableMap;
import io.gitlab.jfronny.commons.serialize.SerializerHolder;
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
import io.gitlab.jfronny.gson.Gson;
import io.gitlab.jfronny.gson.GsonBuilder;
import io.gitlab.jfronny.libjf.config.api.ConfigHolder;
import io.gitlab.jfronny.libjf.config.api.ConfigInstance;
import io.gitlab.jfronny.libjf.gson.FabricLoaderGsonGenerator;
import io.gitlab.jfronny.libjf.gson.HiddenAnnotationExclusionStrategy;
import io.gitlab.jfronny.libjf.unsafe.SafeLog;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.CustomValue;
import org.jetbrains.annotations.ApiStatus;
import com.google.common.collect.*;
import io.gitlab.jfronny.commons.serialize.gson.api.*;
import io.gitlab.jfronny.libjf.config.api.*;
import io.gitlab.jfronny.libjf.gson.*;
import io.gitlab.jfronny.libjf.unsafe.*;
import net.fabricmc.loader.api.*;
import net.fabricmc.loader.api.metadata.*;
import org.jetbrains.annotations.*;
import java.lang.reflect.Modifier;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.nio.file.*;
import java.util.*;
public class ConfigHolderImpl implements ConfigHolder {
@ApiStatus.Internal

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.libjf.config.impl;
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
import io.gitlab.jfronny.commons.serialize.gson.api.GsonHolder;
import io.gitlab.jfronny.gson.JsonElement;
import io.gitlab.jfronny.gson.JsonParser;
import io.gitlab.jfronny.gson.stream.JsonWriter;

View File

@ -1,21 +1,16 @@
package io.gitlab.jfronny.libjf.config.impl;
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
import io.gitlab.jfronny.gson.JsonElement;
import io.gitlab.jfronny.gson.stream.JsonWriter;
import io.gitlab.jfronny.libjf.config.api.Entry;
import io.gitlab.jfronny.libjf.config.api.EntryInfo;
import io.gitlab.jfronny.libjf.config.api.WidgetFactory;
import io.gitlab.jfronny.libjf.config.impl.entrypoint.JfConfigSafe;
import io.gitlab.jfronny.libjf.unsafe.SafeLog;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.ButtonWidget;
import io.gitlab.jfronny.commons.serialize.gson.api.*;
import io.gitlab.jfronny.gson.*;
import io.gitlab.jfronny.gson.stream.*;
import io.gitlab.jfronny.libjf.config.api.*;
import io.gitlab.jfronny.libjf.config.impl.entrypoint.*;
import io.gitlab.jfronny.libjf.unsafe.*;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.stream.*;
public class EntryInfoImpl<T> implements EntryInfo<T> {
public Field field;

View File

@ -12,9 +12,9 @@ import io.gitlab.jfronny.libjf.config.api.ConfigHolder;
import io.gitlab.jfronny.libjf.config.api.ConfigInstance;
import io.gitlab.jfronny.libjf.config.api.EntryInfo;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.text.*;
import java.util.function.Consumer;
import java.util.function.Function;
@ -25,24 +25,24 @@ import static net.minecraft.server.command.CommandManager.literal;
public class JfConfigCommand implements ModInitializer {
@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
LiteralArgumentBuilder<ServerCommandSource> c_libjf = literal(LibJf.MOD_ID);
LiteralArgumentBuilder<ServerCommandSource> c_config = literal("config")
.requires((serverCommandSource) -> serverCommandSource.hasPermissionLevel(4))
.executes(context -> {
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] Loaded configs for:"), false);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] Loaded configs for:"), false);
ConfigHolder.getInstance().getRegistered().forEach((s, config) -> {
context.getSource().sendFeedback(new LiteralText("- " + s), false);
context.getSource().sendFeedback(Text.literal("- " + s), false);
});
return Command.SINGLE_SUCCESS;
});
LiteralArgumentBuilder<ServerCommandSource> c_reload = literal("reload").executes(context -> {
ConfigHolder.getInstance().getRegistered().forEach((mod, config) -> config.load());
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] Reloaded configs"), true);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] Reloaded configs"), true);
return Command.SINGLE_SUCCESS;
});
LiteralArgumentBuilder<ServerCommandSource> c_reset = literal("reset").executes(context -> {
context.getSource().sendError(new LiteralText("[libjf-config-v0] Please specify a config to reset"));
context.getSource().sendError(Text.literal("[libjf-config-v0] Please specify a config to reset"));
return Command.SINGLE_SUCCESS;
});
ConfigHolder.getInstance().getRegistered().forEach((id, config) -> {
@ -59,7 +59,7 @@ public class JfConfigCommand implements ModInitializer {
private void registerEntries(ConfigInstance config, String subpath, LiteralArgumentBuilder<ServerCommandSource> c_config, LiteralArgumentBuilder<ServerCommandSource> c_reload, LiteralArgumentBuilder<ServerCommandSource> c_reset, Function<Consumer<LiteralArgumentBuilder<ServerCommandSource>>, LiteralArgumentBuilder<ServerCommandSource>> pathGen) {
c_config.then(pathGen.apply(cns -> {
cns.executes(context -> {
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] " + subpath + " is a category"), false);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] " + subpath + " is a category"), false);
return Command.SINGLE_SUCCESS;
});
for (EntryInfo<?> entry : config.getEntries()) {
@ -68,19 +68,19 @@ public class JfConfigCommand implements ModInitializer {
}));
c_reload.then(pathGen.apply(cns -> cns.executes(context -> {
config.load();
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] Reloaded config for " + subpath), true);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] Reloaded config for " + subpath), true);
return Command.SINGLE_SUCCESS;
})));
c_reset.then(pathGen.apply(cns -> {
cns.executes(context -> {
config.getPresets().get(ConfigInstanceAbstract.CONFIG_PRESET_DEFAULT).run();
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] Reset config for " + subpath), true);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] Reset config for " + subpath), true);
return Command.SINGLE_SUCCESS;
});
config.getPresets().forEach((id2, preset) -> {
cns.then(literal(id2).executes(context -> {
preset.run();
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] Loaded preset " + id2 + " for " + subpath), true);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] Loaded preset " + id2 + " for " + subpath), true);
return Command.SINGLE_SUCCESS;
}));
});
@ -98,13 +98,13 @@ public class JfConfigCommand implements ModInitializer {
private final DynamicCommandExceptionType eType = new DynamicCommandExceptionType(o -> {
if (o instanceof Throwable throwable) {
return new LiteralText("Could not execute command: " + throwable.getMessage());
} else return new LiteralText("Could not execute command");
return Text.literal("Could not execute command: " + throwable.getMessage());
} else return Text.literal("Could not execute command");
});
private <T> void registerEntry(ConfigInstance config, String subpath, LiteralArgumentBuilder<ServerCommandSource> cns, EntryInfo<T> entry) {
LiteralArgumentBuilder<ServerCommandSource> c_entry = literal(entry.getName()).executes(context -> {
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] The value of " + subpath + entry.getName() + " is " + tryRun(entry::getValue)), false);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] The value of " + subpath + entry.getName() + " is " + tryRun(entry::getValue)), false);
return Command.SINGLE_SUCCESS;
});
ArgumentType<?> type = getType(entry);
@ -112,7 +112,7 @@ public class JfConfigCommand implements ModInitializer {
c_entry.then(argument("value", type).executes(context -> {
T value = context.getArgument("value", entry.getValueType());
tryRun(() -> entry.setValue(value));
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] Set " + subpath + entry.getName() + " to " + value), true);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] Set " + subpath + entry.getName() + " to " + value), true);
return Command.SINGLE_SUCCESS;
}));
}
@ -120,7 +120,7 @@ public class JfConfigCommand implements ModInitializer {
for (T enumConstant : entry.getValueType().getEnumConstants()) {
c_entry.then(literal(enumConstant.toString()).executes(context -> {
tryRun(() -> entry.setValue(enumConstant));
context.getSource().sendFeedback(new LiteralText("[libjf-config-v0] Set " + subpath + entry.getName() + " to " + enumConstant), true);
context.getSource().sendFeedback(Text.literal("[libjf-config-v0] Set " + subpath + entry.getName() + " to " + enumConstant), true);
return Command.SINGLE_SUCCESS;
}));
}

View File

@ -1,9 +1,9 @@
package io.gitlab.jfronny.libjf.config.impl;
import io.gitlab.jfronny.commons.throwable.*;
import io.gitlab.jfronny.libjf.LibJf;
import io.gitlab.jfronny.libjf.config.api.ConfigHolder;
import io.gitlab.jfronny.libjf.coprocess.ThreadCoProcess;
import io.gitlab.jfronny.libjf.generic.ThrowingRunnable;
import net.fabricmc.loader.api.FabricLoader;
import java.io.Closeable;

View File

@ -10,9 +10,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import java.util.ArrayList;
@ -49,13 +47,13 @@ public class EntryInfoWidgetBuilder {
else if (type == boolean.class || type == Boolean.class) {
factory = toggle(info, state,
value -> !(Boolean) value,
value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED));
value -> Text.literal((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED));
} else if (type.isEnum()) {
List<T> values = Arrays.asList(info.getValueType().getEnumConstants());
factory = toggle(info, state, value -> {
int index = values.indexOf(value) + 1;
return values.get(index >= values.size() ? 0 : index);
}, value -> new TranslatableText(config.getModId() + ".jfconfig.enum." + type.getSimpleName() + "." + state.cachedValue));
}, value -> Text.translatable(config.getModId() + ".jfconfig.enum." + type.getSimpleName() + "." + state.cachedValue));
} else {
LibJf.LOGGER.error("Invalid entry type in " + info.getName() + ": " + type.getName());
factory = ((screenWidth, textRenderer, done) -> new WidgetFactory.Widget(() -> {}, new ButtonWidget(-10, 0, 0, 0, Text.of(""), null)));
@ -100,7 +98,7 @@ public class EntryInfoWidgetBuilder {
if (!(isNumber && currentInput.isEmpty()) && !currentInput.equals("-") && !currentInput.equals(".")) {
value = sizeFetcher.apply(currentInput);
inLimits = value.doubleValue() >= min && value.doubleValue() <= max;
state.error = inLimits ? null : Tuple.of(widget, new LiteralText(value.doubleValue() < min ?
state.error = inLimits ? null : Tuple.of(widget, Text.literal(value.doubleValue() < min ?
"§cMinimum " + (isNumber? "value" : "length") + (wholeNumber ? " is " + (int) min : " is " + min) :
"§cMaximum " + (isNumber? "value" : "length") + (wholeNumber ? " is " + (int) max : " is " + max)));
}

View File

@ -10,20 +10,18 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.screen.*;
import net.minecraft.text.*;
import java.util.*;
@Environment(EnvType.CLIENT)
public class TinyConfigScreen extends Screen {
public TinyConfigScreen(ConfigInstance config, Screen parent) {
super(new TranslatableText(config.getModId() + ".jfconfig." + config.getCategoryPath() + "title"));
super(Text.translatable(config.getModId() + ".jfconfig." + config.getCategoryPath() + "title"));
this.parent = parent;
this.config = config;
this.widgets = EntryInfoWidgetBuilder.buildWidgets(config);
@ -41,7 +39,7 @@ public class TinyConfigScreen extends Screen {
config.verify();
this.addDrawableChild(new ButtonWidget(4, 6, 80, 20, new TranslatableText("libjf-config-v0.presets"), button -> {
this.addDrawableChild(new ButtonWidget(4, 6, 80, 20, Text.translatable("libjf-config-v0.presets"), button -> {
MinecraftClient.getInstance().setScreen(new PresetsScreen(this, config));
}));
@ -62,13 +60,13 @@ public class TinyConfigScreen extends Screen {
this.addSelectableChild(this.list);
for (Map.Entry<String, ConfigInstance> entry : config.getCategories().entrySet()) {
this.list.addReference(width / 2,
new TranslatableText(entry.getValue().getModId() + ".jfconfig." + entry.getValue().getCategoryPath() + "title"),
Text.translatable(entry.getValue().getModId() + ".jfconfig." + entry.getValue().getCategoryPath() + "title"),
() -> new TinyConfigScreen(entry.getValue(), this));
}
for (WidgetState<?> info : widgets) {
TranslatableText name = new TranslatableText(translationPrefix + info.entry.getName());
MutableText name = Text.translatable(translationPrefix + info.entry.getName());
WidgetFactory.Widget control = info.factory.build(width, textRenderer, done);
ButtonWidget resetButton = new ButtonWidget(width - 155, 0, 40, 20, new TranslatableText("libjf-config-v0.reset"), (button -> {
ButtonWidget resetButton = new ButtonWidget(width - 155, 0, 40, 20, Text.translatable("libjf-config-v0.reset"), (button -> {
info.reset();
control.updateControls().run();
}));
@ -82,7 +80,7 @@ public class TinyConfigScreen extends Screen {
ConfigInstance ci = ConfigHolder.getInstance().get(referencedConfig);
if (ci != null) {
this.list.addReference(width / 2,
new TranslatableText("libjf-config-v0.see-also", new TranslatableText(ci.getModId() + ".jfconfig." + ci.getCategoryPath() + "title")),
Text.translatable("libjf-config-v0.see-also", Text.translatable(ci.getModId() + ".jfconfig." + ci.getCategoryPath() + "title")),
() -> new TinyConfigScreen(ci, this));
}
}
@ -99,7 +97,7 @@ public class TinyConfigScreen extends Screen {
if (hovered.isPresent()) {
for (WidgetState<?> info : widgets) {
Text text = hovered.get();
TranslatableText name = new TranslatableText(this.translationPrefix + info.entry.getName());
MutableText name = Text.translatable(this.translationPrefix + info.entry.getName());
boolean showTooltip = text.equals(name);
String tooltipKey = translationPrefix + info.entry.getName() + ".tooltip";
if (showTooltip && info.error != null) {
@ -110,7 +108,7 @@ public class TinyConfigScreen extends Screen {
showTooltip = false;
List<Text> list = new ArrayList<>();
for (String str : I18n.translate(tooltipKey).split("\n"))
list.add(new LiteralText(str));
list.add(Text.literal(str));
renderTooltip(matrices, list, mouseX, mouseY);
}
}

View File

@ -8,7 +8,7 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.*;
import java.util.Map;
@ -19,7 +19,7 @@ public class PresetsScreen extends Screen {
private PresetListWidget list;
public PresetsScreen(Screen parent, ConfigInstance config) {
super(new TranslatableText("libjf-config-v0.presets"));
super(Text.translatable("libjf-config-v0.presets"));
this.parent = parent;
this.config = config;
}
@ -30,7 +30,7 @@ public class PresetsScreen extends Screen {
this.list = new PresetListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
for (Map.Entry<String, Runnable> entry : config.getPresets().entrySet()) {
this.list.addButton(new ButtonWidget(width / 2 - 100, 0, 200, 20,
new TranslatableText(entry.getKey()),
Text.translatable(entry.getKey()),
button -> {
LibJf.LOGGER.info("Preset selected: " + entry.getKey());
entry.getValue().run();

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.libjf.config.test;
import io.gitlab.jfronny.commons.serialize.gson.GsonIgnore;
import io.gitlab.jfronny.commons.serialize.gson.api.Ignore;
import io.gitlab.jfronny.libjf.config.api.*;
import java.util.ArrayList;
@ -13,7 +13,7 @@ public class TestConfig implements JfConfig {
@Entry(min = -6) public static float floatTest = -5;
@Entry(max = 21) public static double doubleTest = 20;
@Entry public static String dieStr = "lolz";
@Entry @GsonIgnore
@Entry @Ignore
public static String guiOnlyStr = "lolz";
public static String gsonOnlyStr = "lolz";
@Entry public static Test enumTest = Test.Test;

View File

@ -1,10 +1,9 @@
package io.gitlab.jfronny.libjf.data.manipulation.api;
import io.gitlab.jfronny.commons.LazySupplier;
import io.gitlab.jfronny.commons.throwable.*;
import io.gitlab.jfronny.libjf.LibJf;
import io.gitlab.jfronny.libjf.data.manipulation.impl.ResourcePackHook;
import io.gitlab.jfronny.libjf.generic.ThrowingRunnable;
import io.gitlab.jfronny.libjf.generic.ThrowingSupplier;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.resource.ResourcePack;
@ -48,10 +47,10 @@ public class UserResourceEvents {
});
public static final Event<FindResource> FIND_RESOURCE = EventFactory.createArrayBacked(FindResource.class,
(listeners) -> ((type, namespace, prefix, maxDepth, pathFilter, previous, pack) -> {
(listeners) -> ((type, namespace, prefix, allowedPathPredicate, previous, pack) -> {
LazySupplier<Collection<Identifier>> lazy = new LazySupplier<>(previous);
for (FindResource listener : listeners) {
lazy = lazy.andThen(supplier -> listener.findResources(type, namespace, prefix, maxDepth, pathFilter, supplier, pack));
lazy = lazy.andThen(supplier -> listener.findResources(type, namespace, prefix, allowedPathPredicate, supplier, pack));
}
return lazy.get();
}));
@ -93,7 +92,7 @@ public class UserResourceEvents {
}
public interface FindResource {
Collection<Identifier> findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter, Supplier<Collection<Identifier>> previous, ResourcePack pack);
Collection<Identifier> findResources(ResourceType type, String namespace, String prefix, Predicate<Identifier> allowedPathPredicate, Supplier<Collection<Identifier>> previous, ResourcePack pack);
}
public interface Open {

View File

@ -50,8 +50,8 @@ public class ResourcePackHook {
throw ex;
}
}
public static Collection<Identifier> hookFindResources(Collection<Identifier> value, ResourcePack pack, ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter) {
return isDisabled() ? value : UserResourceEvents.FIND_RESOURCE.invoker().findResources(type, namespace, prefix, maxDepth, pathFilter, new LazySupplier<>(value), pack);
public static Collection<Identifier> hookFindResources(Collection<Identifier> value, ResourcePack pack, ResourceType type, String namespace, String prefix, Predicate<Identifier> allowedPathPredicate) {
return isDisabled() ? value : UserResourceEvents.FIND_RESOURCE.invoker().findResources(type, namespace, prefix, allowedPathPredicate, new LazySupplier<>(value), pack);
}
public static InputStream hookOpenRoot(InputStream value, ResourcePack pack, String fileName) throws IOException {
if (isDisabled()) return value;

View File

@ -37,8 +37,8 @@ public class ResourcePackHookPatch implements AsmConfig {
hookReturn(method, "hookOpen", "Ljava/io/InputStream;", new String[]{"net/minecraft/class_3264", "net/minecraft/class_2960"});
}),
// find resource
new MethodModificationPatch.MethodDescriptorPatch("method_14408", "(Lnet/minecraft/class_3264;Ljava/lang/String;Ljava/lang/String;ILjava/util/function/Predicate;)Ljava/util/Collection;", (method, klazz) -> {
hookReturn(method, "hookFindResources", "Ljava/util/Collection;", new String[]{"net/minecraft/class_3264", "java/lang/String", "java/lang/String", "I", "java/util/function/Predicate"});
new MethodModificationPatch.MethodDescriptorPatch("method_14408", "(Lnet/minecraft/class_3264;Ljava/lang/String;Ljava/lang/String;Ljava/util/function/Predicate;)Ljava/util/Collection;", (method, klazz) -> {
hookReturn(method, "hookFindResources", "Ljava/util/Collection;", new String[]{"net/minecraft/class_3264", "java/lang/String", "java/lang/String", "java/util/function/Predicate"});
}),
// contains
new MethodModificationPatch.MethodDescriptorPatch("method_14411", "(Lnet/minecraft/class_3264;Lnet/minecraft/class_2960;)Z", (method, klazz) -> {

View File

@ -4,6 +4,8 @@ import com.mojang.authlib.minecraft.TelemetryEvent;
import com.mojang.authlib.minecraft.TelemetryPropertyContainer;
import com.mojang.authlib.minecraft.TelemetrySession;
import com.mojang.authlib.minecraft.UserApiService;
import com.mojang.authlib.yggdrasil.response.*;
import org.jetbrains.annotations.*;
import java.util.Set;
import java.util.UUID;
@ -94,4 +96,10 @@ public class NoOpUserApi implements UserApiService {
}
};
}
@Nullable
@Override
public KeyPairResponse getKeyPair() {
return null;
}
}

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.libjf.unsafe;
import io.gitlab.jfronny.commons.log.Logger;
import io.gitlab.jfronny.commons.serialize.gson.GsonHolder;
import io.gitlab.jfronny.commons.serialize.gson.api.GsonHolder;
import io.gitlab.jfronny.libjf.Flags;
import io.gitlab.jfronny.libjf.gson.HiddenAnnotationExclusionStrategy;
import io.gitlab.jfronny.libjf.unsafe.inject.FabricLauncherClassUnlocker;

View File

@ -2,5 +2,5 @@ archivesBaseName = "libjf-web-v0"
dependencies {
moduleDependencies(project, ["libjf-base", "libjf-config-v0"])
include modImplementation(fabricApi.module("fabric-command-api-v1", "${rootProject.fabric_version}"))
include modImplementation(fabricApi.module("fabric-command-api-v2", "${rootProject.fabric_version}"))
}

View File

@ -6,8 +6,8 @@ import io.gitlab.jfronny.libjf.LibJf;
import io.gitlab.jfronny.libjf.coprocess.CoProcess;
import io.gitlab.jfronny.libjf.web.api.WebServer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.minecraft.text.LiteralText;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.text.*;
import static net.minecraft.server.command.CommandManager.literal;
@ -31,23 +31,23 @@ public class JfWeb implements CoProcess, ModInitializer {
@Override
public void onInitialize() {
if (isEnabled()) {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(literal(LibJf.MOD_ID).then(literal("web").requires((serverCommandSource) -> serverCommandSource.hasPermissionLevel(4)).executes(context -> {
if (SERVER.isActive()) {
context.getSource().sendFeedback(new LiteralText("LibWeb is active. Use libweb restart to reload"), false);
context.getSource().sendFeedback(Text.literal("LibWeb is active. Use libweb restart to reload"), false);
}
else {
context.getSource().sendFeedback(new LiteralText("LibWeb is not active. Use libweb restart to reload"), false);
context.getSource().sendFeedback(Text.literal("LibWeb is not active. Use libweb restart to reload"), false);
}
return Command.SINGLE_SUCCESS;
}).then(literal("restart").executes(context -> {
try {
context.getSource().sendFeedback(new LiteralText("Restarting LibWeb"), true);
context.getSource().sendFeedback(Text.literal("Restarting LibWeb"), true);
SERVER.restart();
}
catch (Exception e) {
LibJf.LOGGER.error("Failed to run restart command", e);
context.getSource().sendError(new LiteralText(e.getMessage()));
context.getSource().sendError(Text.literal(e.getMessage()));
}
return Command.SINGLE_SUCCESS;
}))));

View File

@ -23,7 +23,7 @@
"libjf-base": ">=${version}",
"libjf-config-v0": ">=${version}",
"fabric-lifecycle-events-v1": "*",
"fabric-command-api-v1": "*"
"fabric-command-api-v2": "*"
},
"custom": {
"modmenu": {