Skip to content

Commit

Permalink
everything is fine 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
RawDiamondMC committed Oct 4, 2024
1 parent bae9376 commit 73ea2d7
Show file tree
Hide file tree
Showing 100 changed files with 199 additions and 380 deletions.
56 changes: 14 additions & 42 deletions base/common/src/main/java/band/kessoku/lib/api/KessokuLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@
package band.kessoku.lib.api;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;

import band.kessoku.lib.impl.base.KessokuUtils;
import org.jetbrains.annotations.UnmodifiableView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class KessokuLib {
private static final List<Class<?>> initializedModules = new ArrayList<>();

private KessokuLib() {
}

public static void loadModule(Class<?> moduleCommonClass, Object... args) {
public static void loadModule(Class<?> moduleCommonClass) {
// Try to get module name
String moduleName;
try {
Expand All @@ -43,46 +39,14 @@ public static void loadModule(Class<?> moduleCommonClass, Object... args) {
field.setAccessible(true);
moduleName = (String) field.get(null);
} catch (NoSuchFieldException e) {
KessokuUtils.getLogger().warn("no NAME found for {}! Using package name", moduleCommonClass.getPackageName());
getLogger().warn("no NAME found for {}! Using package name", moduleCommonClass.getPackageName());
moduleName = moduleCommonClass.getPackageName();
} catch (IllegalAccessException e) {
// Already set accessible, shouldn't be called
moduleName = moduleCommonClass.getPackageName();
}

// Modules shouldn't be able to load for multiple times
if (isModuleLoaded(moduleCommonClass)) {
throw new UnsupportedOperationException(moduleName + " is already loaded!");
}

// Get init method
Class<?>[] argClasses = (Class<?>[]) Arrays.stream(args).map(Object::getClass).toArray();
Method method;
try {
method = moduleCommonClass.getMethod("init", argClasses);
} catch (NoSuchMethodException e) {
// The module doesn't need to be initialized
initializedModules.add(moduleCommonClass);
KessokuUtils.getLogger().info("{} loaded!", moduleName);
return;
}

// init method should be static
if (!Modifier.isStatic(method.getModifiers())) {
KessokuUtils.getLogger().error("init method of {} is not static!", moduleName);
return;
}

method.setAccessible(true);

// initialize module
try {
method.invoke(null, args);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to initialize Kessoku Module " + moduleName + " !");
}
initializedModules.add(moduleCommonClass);
KessokuUtils.getLogger().info("{} loaded!", moduleName);
getLogger().info("{} loaded!", moduleName);
}

public static boolean isModuleLoaded(Class<?> moduleCommonClass) {
Expand All @@ -93,4 +57,12 @@ public static boolean isModuleLoaded(Class<?> moduleCommonClass) {
public static List<Class<?>> getActiveModules() {
return Collections.unmodifiableList(initializedModules);
}

public static <T> T loadService(final Class<T> clazz) {
return ServiceLoader.load(clazz).findFirst().orElseThrow(() -> new AssertionError("No impl found for " + clazz.getPackageName()));
}

public static Logger getLogger() {
return LoggerFactory.getLogger("[Kessoku Lib]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.impl.base;
package band.kessoku.lib.api.base;

import java.lang.reflect.Constructor;
import java.util.*;

import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class KessokuUtils {
private KessokuUtils() {
}

public static <T> T loadService(final Class<T> clazz) {
return ServiceLoader.load(clazz).findFirst().orElseThrow(() -> new AssertionError("No impl found for " + clazz.getPackageName()));
}

public static Logger getLogger() {
return LoggerFactory.getLogger("[Kessoku Lib]");
}

public static <T> boolean isType(final List<?> list, final Class<T> type) {
for (final Object element : list) {
if (!(type.isInstance(element))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.event.api.util.neo;
package band.kessoku.lib.api.base.neoforge;

import java.util.function.Consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.events.command;
package band.kessoku.lib.api.event.command;

import band.kessoku.lib.event.api.Event;
import com.mojang.brigadier.CommandDispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package kessoku.testmod.command;

import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer;
import band.kessoku.lib.api.events.command.CommandRegistryEvent;
import band.kessoku.lib.api.event.command.CommandRegistryEvent;

import net.minecraft.server.command.CommandManager;
import net.minecraft.text.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package band.kessoku.lib.impl.command.fabric;

import band.kessoku.lib.api.events.command.CommandRegistryEvent;
import band.kessoku.lib.api.event.command.CommandRegistryEvent;

import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;

Expand Down
2 changes: 1 addition & 1 deletion command/neo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ base.archivesName = rootProject.name + "-command"

kessoku {
modules(["base", "event-base"], "common")
module("event-base", "neo")
module("base", "neo")

common("command", ModPlatform.NEOFORGE)
shadowBundle("command", ModPlatform.NEOFORGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package band.kessoku.lib.impl.command.neoforge;

import band.kessoku.lib.api.events.command.CommandRegistryEvent;
import band.kessoku.lib.event.api.util.neo.NeoEventUtils;
import band.kessoku.lib.api.base.neoforge.NeoEventUtils;
import band.kessoku.lib.api.event.command.CommandRegistryEvent;

import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import band.kessoku.lib.api.KessokuLib;
import band.kessoku.lib.api.config.annotations.Comment;
import band.kessoku.lib.api.config.annotations.Comments;
import band.kessoku.lib.api.config.annotations.Name;
import band.kessoku.lib.impl.base.KessokuUtils;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -92,13 +92,13 @@ public boolean load() {
ConfigValue.Type type = ConfigValue.Type.asType(cValue);
// Check if the type is valid to deserialize
if (type == ConfigValue.Type.NULL) {
KessokuUtils.getLogger().error(KessokuConfig.MARKER, "Illegal type`{}` found in the file!", cValue.getClass().getName());
KessokuLib.getLogger().error(KessokuConfig.MARKER, "Illegal type`{}` found in the file!", cValue.getClass().getName());
continue;
}

// Check if the type matches the value's type
if (value.getType() != type) {
KessokuUtils.getLogger().error(KessokuConfig.MARKER, "Illegal type`{}` found in the file! Expect {}.", type.toString().toLowerCase(), value.getType().toString().toLowerCase());
KessokuLib.getLogger().error(KessokuConfig.MARKER, "Illegal type`{}` found in the file! Expect {}.", type.toString().toLowerCase(), value.getType().toString().toLowerCase());
continue;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ private Map<String, ValueWithComment> serialize() {
AbstractConfig category = (AbstractConfig) fieldValue;
if (this.split) {
if (!category.save()) {
KessokuUtils.getLogger().error(KessokuConfig.MARKER, "Failed to save category `{}!`", category.getSimpleName());
KessokuLib.getLogger().error(KessokuConfig.MARKER, "Failed to save category `{}!`", category.getSimpleName());
}
continue;
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* When building structure, data must be member variable and {@link DataStructure#integrate(Data) "integrate()"}
* can be used to hold data for other usages.
* </p>
* @see AbstractNBTStructure There also is an abstract structure for using.
*/
public interface DataStructure {
<T, K extends Data<T>> K integrate(K data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.impl.data;
package band.kessoku.lib.api.data;

import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion data/common/src/main/resources/kessoku_data.mixins.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"required": true,
"package": "band.kessoku.lib.mixins.data",
"package": "band.kessoku.lib.mixin.data",
"compatibilityLevel": "JAVA_21",
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package band.kessoku.lib.impl.data.fabric;

import band.kessoku.lib.api.KessokuLib;
import band.kessoku.lib.impl.data.KessokuData;
import band.kessoku.lib.api.data.KessokuData;

import net.fabricmc.api.ModInitializer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package band.kessoku.lib.impl.data.neoforge;

import band.kessoku.lib.api.KessokuLib;
import band.kessoku.lib.impl.data.KessokuData;
import band.kessoku.lib.api.data.KessokuData;

import net.neoforged.fml.common.Mod;

Expand Down
Loading

0 comments on commit 73ea2d7

Please sign in to comment.