diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..e42b46e --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,79 @@ + + + 4.0.0 + com.cimeyclust.addonreader.resources + CustomResources + 1.1.0 + + clean package + + + true + src/main/resources + + + ${project.name} + + + maven-shade-plugin + 3.3.0 + + + package + + shade + + + + + cn.nukkit.nukkit + org.junit.jupiter.junit-jupiter-engine + + + + + + + + maven-compiler-plugin + + 17 + 17 + + + + maven-surefire-plugin + 2.22.0 + + + + + + gitea + https://repo.cimeyclust.com/api/packages/CimeyClust/maven + + + + + cn.powernukkitx + powernukkitx + 1.20.10-r1 + provided + + + + + gitea + https://repo.cimeyclust.com/api/packages/CimeyClust/maven + + + gitea + https://repo.cimeyclust.com/api/packages/CimeyClust/maven + + + + 17 + 17 + UTF-8 + + diff --git a/pom.xml b/pom.xml index f72015b..dff7613 100644 --- a/pom.xml +++ b/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.cimeyclust.addonreader.custom_blocks + com.cimeyclust.addonreader.resources CustomResources - 1.0-SNAPSHOT + 1.1.0 17 @@ -21,6 +21,17 @@ + + + gitea + https://repo.cimeyclust.com/api/packages/CimeyClust/maven + + + gitea + https://repo.cimeyclust.com/api/packages/CimeyClust/maven + + + ${project.name} clean package @@ -78,9 +89,9 @@ provided - com.cimeyclust.addonreader - NukkitAddonReader - 2.0.2 + org.reflections + reflections + 0.10.2 \ No newline at end of file diff --git a/src/main/java/com/cimeyclust/addonreader/resources/Plugin.java b/src/main/java/com/cimeyclust/addonreader/resources/Plugin.java new file mode 100644 index 0000000..7491cb5 --- /dev/null +++ b/src/main/java/com/cimeyclust/addonreader/resources/Plugin.java @@ -0,0 +1,90 @@ +package com.cimeyclust.addonreader.resources; + +import cn.nukkit.block.Block; +import cn.nukkit.block.customblock.CustomBlock; +import cn.nukkit.entity.Entity; +import cn.nukkit.entity.custom.CustomEntity; +import cn.nukkit.entity.provider.CustomClassEntityProvider; +import cn.nukkit.item.Item; +import cn.nukkit.item.customitem.CustomItem; +import cn.nukkit.plugin.PluginBase; +import org.reflections.Reflections; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class Plugin extends PluginBase { + private static Plugin instance; + private List> entities; + + @Override + public void onLoad() { + instance = this; + entities = new ArrayList<>(); + } + + @Override + public void onEnable() { + // Register Blocks + Reflections blockReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_blocks"); + Set> blocks = blockReflections.getSubTypesOf(Object.class).stream() + .filter(clazz -> clazz.getSuperclass() == CustomBlock.class) + .map(clazz -> (Class) clazz) + .collect(Collectors.toSet()); + + for (Class clazz : blocks) { + getLogger().info("§aLoading custom block " + clazz + "..."); + try { + Block.registerCustomBlock(Collections.singletonList(clazz)).assertOK(); + } catch (AssertionError e) { + e.printStackTrace(); + } + } + + // Register Items + Reflections itemReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_items"); + Set> items = itemReflections.getSubTypesOf(Object.class).stream() + .filter(clazz -> clazz.getSuperclass() == CustomItem.class) + .map(clazz -> (Class) clazz) + .collect(Collectors.toSet()); + + for (Class clazz : items) { + try { + Item.registerCustomItem(clazz).assertOK(); + } catch (AssertionError e) { + e.printStackTrace(); + } + } + + // Register Entities + Reflections entityReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_entities"); + Set> entities = itemReflections.getSubTypesOf(Object.class).stream() + .filter(clazz -> clazz.getSuperclass() == Entity.class) + .map(clazz -> (Class) clazz) + .collect(Collectors.toSet()); + + for (Class clazz : entities) { + try { + Entity.registerCustomEntity(new CustomClassEntityProvider(clazz)).assertOK(); + entities.add(clazz); + } catch (AssertionError e) { + e.printStackTrace(); + } + } + } + + public static Plugin getInstance() { + return instance; + } + + public List> getEntities() { + return entities; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..d729f47 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,8 @@ +name: CustomResources +description: Stores and loads custom resources. +main: com.cimeyclust.addonreader.resources.Plugin +api: [ "1.0.0" ] +version: ${project.version} +author: Verox +website: https://cimeyclust.com +depend: []