merged old changes

This commit is contained in:
UnrealValentin
2021-04-29 18:16:46 +02:00
14 changed files with 106 additions and 42 deletions

View File

@@ -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;
}
}

View File

@@ -1,10 +0,0 @@
package org.hmcore.registration.config;
public class ObjectInfoConfig {
public final ModuleInfo[] modules;
public ObjectInfoConfig(ModuleInfo[] modules) {
this.modules = modules;
}
}

View File

@@ -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 [!]");
}
}

View File

@@ -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;
}
}

View 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]) }

View File

@@ -0,0 +1,6 @@
package org.hmcore.registration.config
internal class ModuleInfo(
@JvmField val moduleName: String,
@JvmField val objects: Array<ObjectInfoData>,
)

View File

@@ -0,0 +1,5 @@
package org.hmcore.registration.config
internal class ObjectInfoConfig(
@JvmField val modules: Array<ModuleInfo>,
)

View File

@@ -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) }))

View File

@@ -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",
)

View File

@@ -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

View File

@@ -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<>();