Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Attention][Feature] Rewrite config #21

Open
wants to merge 25 commits into
base: dev/1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1656796
🐺🚧📕🔧💻✔️💾🚀️
AmarokIce Dec 22, 2024
c3f8fa2
🐺🚧📕🔧💻✔️💾🚀️
AmarokIce Dec 22, 2024
053b2bc
🐺📰
AmarokIce Dec 24, 2024
46203a1
🐺🚧
AmarokIce Dec 24, 2024
01c69c9
chore: Apply Spotless
github-actions[bot] Dec 24, 2024
d094dfa
🐺❓
AmarokIce Dec 24, 2024
1cc3730
Merge branch 'dev/config' of https://github.com/KessokuTeaTime/Kessok…
AmarokIce Dec 24, 2024
e487dd3
🐺🚧🚀
AmarokIce Dec 25, 2024
21841a1
chore: Apply Spotless
github-actions[bot] Dec 25, 2024
2aa4eba
🐺🦀
AmarokIce Dec 27, 2024
1e6de53
Merge remote-tracking branch 'origin/dev/config' into dev/config
AmarokIce Dec 27, 2024
55ead24
🐺💾🪡🔩
AmarokIce Dec 27, 2024
a9d2ba1
chore: Apply Spotless
github-actions[bot] Dec 27, 2024
719e663
🐺💾🪡🔩
AmarokIce Jan 13, 2025
14cd07f
chore: Apply Spotless
github-actions[bot] Jan 13, 2025
397f236
🐺🪡🔩🚀
AmarokIce Jan 31, 2025
bd8eabf
Merge branch 'dev/config' of https://github.com/KessokuTeaTime/Kessok…
AmarokIce Jan 31, 2025
782d262
chore: Apply Spotless
github-actions[bot] Jan 31, 2025
beb2460
🐺🚀🎶
AmarokIce Feb 1, 2025
321868d
Merge remote-tracking branch 'origin/dev/config' into dev/config
AmarokIce Feb 1, 2025
63c46aa
chore: Apply Spotless
github-actions[bot] Feb 1, 2025
786ad36
🐺❌
AmarokIce Feb 3, 2025
554f678
chore: Apply Spotless
github-actions[bot] Feb 3, 2025
12bbb73
🐺📰🎶
AmarokIce Feb 4, 2025
194b30a
chore: Apply Spotless
github-actions[bot] Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 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,13 +16,9 @@
package band.kessoku.lib.api;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ServiceLoader;
import java.lang.reflect.Modifier;
import java.util.*;

import org.apache.logging.log4j.core.util.ReflectionUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnmodifiableView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -33,23 +29,22 @@ public final class KessokuLib {
private KessokuLib() {
}

public static void loadModule(@NotNull final Class<?> moduleCommonClass) {
if (moduleCommonClass.isArray())
throw new UnsupportedOperationException("What the hell are you doing?? KessokuLib.loadModule receives an array class! " + moduleCommonClass.getName());
if (isModuleLoaded(moduleCommonClass)) {
throw new UnsupportedOperationException("Module `" + moduleCommonClass.getName() + "` has already been loaded!");
}
public static void loadModule(Class<?> moduleCommonClass) {
// Try to get module name
final String moduleName;
String moduleName;
try {
final Field field = moduleCommonClass.getField("NAME");
moduleName = (String) ReflectionUtil.getStaticFieldValue(field);
Field field = moduleCommonClass.getField("NAME");
if (!Modifier.isStatic(field.getModifiers())) {
throw new IllegalArgumentException("NAME in " + moduleCommonClass.getPackageName() + " is not static!");
}
field.setAccessible(true);
moduleName = (String) field.get(null);
} catch (NoSuchFieldException e) {
getLogger().error("Invalid Kessoku module! Field `NAME` is not found in {}!", moduleCommonClass.getName());
return;
} catch (NullPointerException e) {
getLogger().error("Invalid Kessoku module! NAME in {} is not static!", moduleCommonClass.getName());
return;
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();
}
initializedModules.add(moduleCommonClass);
getLogger().info("{} loaded!", moduleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package band.kessoku.lib.api.base.reflect;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.util.Arrays;

import band.kessoku.lib.api.KessokuLib;

public final class ReflectUtil {
private ReflectUtil() {
}
Expand All @@ -31,4 +34,14 @@ public static boolean isAssignableFrom(Object o, Class<?>... classes) {
var flag = Arrays.stream(classes).anyMatch(clazz -> !o.getClass().isAssignableFrom(clazz));
return !flag;
}

public static boolean markAccessible(AccessibleObject obj) {
try {
obj.setAccessible(true);
return true;
} catch (Exception e) {
KessokuLib.getLogger().error(e.getMessage(), e);
return false;
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading