mirror of
https://github.com/HMCore/Core.git
synced 2025-12-12 13:56:19 +00:00
merged old changes
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package org.hmcore.registration.config;
|
||||
|
||||
public class ModuleInfo {
|
||||
|
||||
public final String moduleName;
|
||||
public final ObjectInfoData[] objects;
|
||||
|
||||
public ModuleInfo(String moduleName, ObjectInfoData[] objects) {
|
||||
this.moduleName = moduleName;
|
||||
this.objects = objects;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package org.hmcore.registration.config;
|
||||
|
||||
public class ObjectInfoConfig {
|
||||
|
||||
public final ModuleInfo[] modules;
|
||||
|
||||
public ObjectInfoConfig(ModuleInfo[] modules) {
|
||||
this.modules = modules;
|
||||
}
|
||||
}
|
||||
@@ -43,10 +43,10 @@ public class ObjectInfoConfigHandler {
|
||||
RegistryModule<?, ?> registryModule = (RegistryModule<?, ?>) module;
|
||||
for (ObjectInfoData data:
|
||||
moduleInfo.objects) {
|
||||
if(registryModule.objectAndInfoExist(data.objectName, data.objectInfoChoosen)) {
|
||||
registryModule.forceObjectInfoForObject(data.objectName, data.objectInfoChoosen);
|
||||
if(registryModule.objectAndInfoExist(data.objectInfoName, data.objectInfoChosen)) {
|
||||
registryModule.forceObjectInfoForObject(data.objectInfoName, data.objectInfoChosen);
|
||||
} else {
|
||||
System.out.println("[!] Either Object Info " + data.objectInfoChoosen + " doesn't exist for " + data.objectName + " or " + data.objectName + " doesn't exist!\n" +
|
||||
System.out.println("[!] Either Object Info " + data.objectInfoChosen + " doesn't exist for " + data.objectInfoName + " or " + data.objectInfoName + " doesn't exist!\n" +
|
||||
"Please stop the Server, delete objetc-infos.json and let the server regenertate a new config [!]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.hmcore.registration.config;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ObjectInfoData {
|
||||
|
||||
public final String objectName;
|
||||
public final String objectInfoChoosen;
|
||||
public final String _availableOptions;
|
||||
|
||||
public ObjectInfoData(String objectName, @Nullable String objectInfoChoosen, String availableOptions) {
|
||||
this.objectName = objectName;
|
||||
this.objectInfoChoosen = objectInfoChoosen == null ? "default" : objectInfoChoosen;
|
||||
_availableOptions = availableOptions;
|
||||
}
|
||||
}
|
||||
7
src/main/kotlin/extensions/Array.kt
Normal file
7
src/main/kotlin/extensions/Array.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package extensions
|
||||
|
||||
/**
|
||||
* Map a Java array to another Java array
|
||||
*/
|
||||
inline fun <T, reified I> Array<T>.map(crossinline transform: (T) -> I) =
|
||||
Array(size) { transform(this[it]) }
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.hmcore.registration.config
|
||||
|
||||
internal class ModuleInfo(
|
||||
@JvmField val moduleName: String,
|
||||
@JvmField val objects: Array<ObjectInfoData>,
|
||||
)
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.hmcore.registration.config
|
||||
|
||||
internal class ObjectInfoConfig(
|
||||
@JvmField val modules: Array<ModuleInfo>,
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
@file:JvmName("ObjectInfoConfigHandler")
|
||||
|
||||
package org.hmcore.registration.config
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import org.hmcore.modules.Module
|
||||
import extensions.map
|
||||
|
||||
private val GSON = GsonBuilder().setPrettyPrinting().create()
|
||||
|
||||
internal fun Array<Module<*, *>>.generateFreshJSON(): String =
|
||||
GSON.toJson(ObjectInfoConfig(map { ModuleInfo(it.name, it.objectInfoArray) }))
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.hmcore.registration.config
|
||||
|
||||
internal class ObjectInfoData @JvmOverloads constructor(
|
||||
@JvmField val objectInfoName: String,
|
||||
@JvmField val availableOptions: String,
|
||||
@JvmField val objectInfoChosen: String = "default",
|
||||
)
|
||||
@@ -12,6 +12,7 @@ import java.io.FileNotFoundException;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SuppressWarnings("KotlinInternalInJava")
|
||||
public class JavaTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("KotlinInternalInJava")
|
||||
public class JavaTestRegistryModule extends RegistryModule<Integer, JavaCustomObjectInfo> {
|
||||
|
||||
public HashMap<String, Integer> objectMap = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user