Made CustomResources a plugin
This commit is contained in:
parent
176ebe6498
commit
21be35ff3c
79
dependency-reduced-pom.xml
Normal file
79
dependency-reduced-pom.xml
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.cimeyclust.addonreader.resources</groupId>
|
||||||
|
<artifactId>CustomResources</artifactId>
|
||||||
|
<version>1.1.0</version>
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean package</defaultGoal>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<finalName>${project.name}</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactSet>
|
||||||
|
<excludes>
|
||||||
|
<exclude>cn.nukkit.nukkit</exclude>
|
||||||
|
<exclude>org.junit.jupiter.junit-jupiter-engine</exclude>
|
||||||
|
</excludes>
|
||||||
|
</artifactSet>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>17</source>
|
||||||
|
<target>17</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>https://repo.cimeyclust.com/api/packages/CimeyClust/maven</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.powernukkitx</groupId>
|
||||||
|
<artifactId>powernukkitx</artifactId>
|
||||||
|
<version>1.20.10-r1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>https://repo.cimeyclust.com/api/packages/CimeyClust/maven</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>https://repo.cimeyclust.com/api/packages/CimeyClust/maven</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
</project>
|
||||||
21
pom.xml
21
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.cimeyclust.addonreader.custom_blocks</groupId>
|
<groupId>com.cimeyclust.addonreader.resources</groupId>
|
||||||
<artifactId>CustomResources</artifactId>
|
<artifactId>CustomResources</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
@ -21,6 +21,17 @@
|
|||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>https://repo.cimeyclust.com/api/packages/CimeyClust/maven</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>gitea</id>
|
||||||
|
<url>https://repo.cimeyclust.com/api/packages/CimeyClust/maven</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
<defaultGoal>clean package</defaultGoal>
|
<defaultGoal>clean package</defaultGoal>
|
||||||
@ -78,9 +89,9 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.cimeyclust.addonreader</groupId>
|
<groupId>org.reflections</groupId>
|
||||||
<artifactId>NukkitAddonReader</artifactId>
|
<artifactId>reflections</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>0.10.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -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<Class <? extends Entity>> 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<Class<? extends CustomBlock>> blocks = blockReflections.getSubTypesOf(Object.class).stream()
|
||||||
|
.filter(clazz -> clazz.getSuperclass() == CustomBlock.class)
|
||||||
|
.map(clazz -> (Class<? extends CustomBlock>) clazz)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
for (Class<? extends CustomBlock> 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<Class<? extends CustomItem>> items = itemReflections.getSubTypesOf(Object.class).stream()
|
||||||
|
.filter(clazz -> clazz.getSuperclass() == CustomItem.class)
|
||||||
|
.map(clazz -> (Class<? extends CustomItem>) clazz)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
for (Class<? extends CustomItem> 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<Class<? extends Entity>> entities = itemReflections.getSubTypesOf(Object.class).stream()
|
||||||
|
.filter(clazz -> clazz.getSuperclass() == Entity.class)
|
||||||
|
.map(clazz -> (Class<? extends Entity>) clazz)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
for (Class<? extends Entity> 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<Class<? extends Entity>> getEntities() {
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/main/resources/plugin.yml
Normal file
8
src/main/resources/plugin.yml
Normal file
@ -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: []
|
||||||
Loading…
x
Reference in New Issue
Block a user