mirror of
https://github.com/HMCore/Core.git
synced 2025-12-12 13:56:19 +00:00
Initial data push
This commit is contained in:
15
src/main/java/org/hmcore/HMCore.java
Normal file
15
src/main/java/org/hmcore/HMCore.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package org.hmcore;
|
||||
|
||||
import org.hmcore.modules.Module;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class HMCore {
|
||||
|
||||
public static HashMap<String, Module<?, ?>> modules = new HashMap<>();
|
||||
|
||||
public static void callAllModuleRegistries() {
|
||||
modules.forEach((name, module) -> module.registerObjects());
|
||||
}
|
||||
|
||||
}
|
||||
72
src/main/java/org/hmcore/modules/Module.java
Normal file
72
src/main/java/org/hmcore/modules/Module.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package org.hmcore.modules;
|
||||
|
||||
import org.hmcore.registration.ObjectInfo;
|
||||
|
||||
/**
|
||||
* Represents a module that manages the objects that should get registered to Hytale.
|
||||
* @param <T> The object that should get registered
|
||||
* @param <I> Object that contains informations about the object. Like the texture.
|
||||
*/
|
||||
public abstract class Module<T, I extends ObjectInfo> {
|
||||
|
||||
//
|
||||
// For registering Objects to Module and getting them
|
||||
// Made for mods to call them
|
||||
//
|
||||
|
||||
/**
|
||||
* For checking if the Module has the module already in its list.
|
||||
* @param name The name or registration key of the object to be checked
|
||||
* @return true when the object is already registered.
|
||||
*/
|
||||
public abstract boolean contains(String name);
|
||||
|
||||
/**
|
||||
* Gets the object for the registered name.
|
||||
* @param name The name or key for the object that should be returned.
|
||||
* @return The object under the registered name or null if it doesn't exists.
|
||||
*/
|
||||
public abstract T get(String name);
|
||||
|
||||
/**
|
||||
* Registeres the object to the module.
|
||||
* @param name The name or key for the object to get registered under.
|
||||
* @param object The object that should get registered.
|
||||
*/
|
||||
public abstract void register(String name, T object);
|
||||
|
||||
// TODO: If one option added stuff the other option doesn't had, (as example ore generation info for a block) it should be automatically added.
|
||||
// TODO: The admins should be able to choose a option for each feature individually. (Block behavior, ore generation, maybe force a specific texture for users, etc.)
|
||||
|
||||
/**
|
||||
* Adds an option for information to the object.
|
||||
* There can be multiple options for information and the server administrators can choose which to use.
|
||||
* Per default the first registered option is used.
|
||||
* @param name The name or key for the object the information should be added to.
|
||||
* @param infoName The name of the option. The name of the mod as example.
|
||||
* @param objectInfo The info object that supplies the module with the required information.
|
||||
*/
|
||||
public abstract void addInfoToObject(String name, String infoName, I objectInfo);
|
||||
|
||||
/**
|
||||
* Simple utility function that automatically checks if the object already exists.
|
||||
* If not, the object is registered. An easy boilerplate code pevention.
|
||||
* @param name
|
||||
* @param object
|
||||
*/
|
||||
public void registerIfNonExistant(String name, T object) {
|
||||
if(!contains(name)) register(name, object);
|
||||
}
|
||||
|
||||
//
|
||||
// For registering the Objects to Hytale
|
||||
// Made for internal use ONLY
|
||||
//
|
||||
|
||||
/**
|
||||
* Gets called when the phase of object registration to hytale has come.
|
||||
* @return true when every object has been registered successfully.
|
||||
*/
|
||||
public abstract boolean registerObjects();
|
||||
|
||||
}
|
||||
5
src/main/kotlin/org/hmcore/registration/ObjectInfo.kt
Normal file
5
src/main/kotlin/org/hmcore/registration/ObjectInfo.kt
Normal file
@@ -0,0 +1,5 @@
|
||||
package org.hmcore.registration
|
||||
|
||||
open class ObjectInfo(val texturePath: String) {
|
||||
|
||||
}
|
||||
45
src/test/java/org/hmcore/tests/JavaTests.java
Normal file
45
src/test/java/org/hmcore/tests/JavaTests.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package org.hmcore.tests;
|
||||
|
||||
import org.hmcore.HMCore;
|
||||
import org.hmcore.tests.modules.impl.JavaTestModule;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class JavaTests {
|
||||
|
||||
@Test
|
||||
public void testModuleFunctionality() {
|
||||
|
||||
HMCore.modules.putIfAbsent("java_test", new JavaTestModule());
|
||||
|
||||
JavaTestModule testModule = (JavaTestModule) HMCore.modules.get("java_test");
|
||||
|
||||
//
|
||||
// Default registration tests
|
||||
//
|
||||
|
||||
testModule.register("test1", 609);
|
||||
|
||||
assertTrue(testModule.contains("test1"), "Module doesn't contain object after registration!");
|
||||
|
||||
assertEquals(609, testModule.get("test1"), "Object has changed properties for some reason!");
|
||||
|
||||
testModule.register("test2", 1256);
|
||||
|
||||
assertTrue(testModule.contains("test2"), "Module doesn't contain object after registration!");
|
||||
|
||||
assertEquals(1256, testModule.get("test2"), "Object has changed properties for some reason!");
|
||||
|
||||
testModule.register("test3", 74232);
|
||||
|
||||
assertTrue(testModule.contains("test3"), "Module doesn't contain object after registration!");
|
||||
|
||||
assertEquals(74232, testModule.get("test3"), "Object has changed properties for some reason!");
|
||||
|
||||
assertTrue(testModule.registerObjects(), "Some weird behavior happened..");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.hmcore.tests.modules.impl;
|
||||
|
||||
import org.hmcore.registration.ObjectInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JavaCustomObjectInfo extends ObjectInfo {
|
||||
|
||||
private final int beanCount;
|
||||
|
||||
public JavaCustomObjectInfo(@NotNull String texturePath, int beanCount) {
|
||||
super(texturePath);
|
||||
this.beanCount = beanCount;
|
||||
}
|
||||
|
||||
public int getBeanCount() {
|
||||
return beanCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.hmcore.tests.modules.impl;
|
||||
|
||||
import org.hmcore.modules.Module;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaTestModule extends Module<Integer, JavaCustomObjectInfo> {
|
||||
|
||||
public HashMap<String, Integer> objectMap = new HashMap<>();
|
||||
public HashMap<String, HashMap<String, JavaCustomObjectInfo>> infoMap = new HashMap<>();
|
||||
|
||||
public List<Object> endList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public boolean contains(String name) {
|
||||
return objectMap.containsKey(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get(String name) {
|
||||
return objectMap.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(String name, Integer object) {
|
||||
objectMap.put(name, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInfoToObject(String name, String infoName, JavaCustomObjectInfo objectInfo) {
|
||||
if(!infoMap.containsKey(name)) infoMap.put(name, new HashMap<>());
|
||||
|
||||
infoMap.get(name).putIfAbsent(infoName, objectInfo);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerObjects() {
|
||||
|
||||
objectMap.forEach((string, integer) -> {
|
||||
endList.add(string);
|
||||
endList.add(integer);
|
||||
});
|
||||
|
||||
infoMap.forEach((string, hashmap) -> {
|
||||
endList.add(string);
|
||||
hashmap.forEach((string2, objectinfo) -> {
|
||||
endList.add(string2);
|
||||
endList.add(objectinfo.getTexturePath());
|
||||
endList.add(objectinfo.getBeanCount());
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user