Added placeholder for class name insertion
This commit is contained in:
parent
ff90f30a59
commit
4044e6ca53
@ -28,23 +28,30 @@ import java.util.stream.Collectors;
|
|||||||
public class Plugin extends PluginBase {
|
public class Plugin extends PluginBase {
|
||||||
private static Plugin instance;
|
private static Plugin instance;
|
||||||
private List<Class <? extends Entity>> entities;
|
private List<Class <? extends Entity>> entities;
|
||||||
|
private ArrayList<String> blockNames;
|
||||||
|
private ArrayList<String> itemNames;
|
||||||
|
private ArrayList<String> entityNames;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
instance = this;
|
instance = this;
|
||||||
entities = new ArrayList<>();
|
entities = new ArrayList<>();
|
||||||
|
entityNames = new ArrayList<>();
|
||||||
|
// %entitynames%
|
||||||
|
blockNames = new ArrayList<>();
|
||||||
|
// %blocknames%
|
||||||
|
itemNames = new ArrayList<>();
|
||||||
|
// %itemnames%
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Register Blocks
|
// Register Blocks
|
||||||
Reflections blockReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_blocks");
|
/*Reflections blockReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_blocks");
|
||||||
|
|
||||||
Reflections reflections = new Reflections(new ConfigurationBuilder()
|
Reflections reflections = new Reflections(new ConfigurationBuilder()
|
||||||
.setUrls(ClasspathHelper.forPackage("com.cimeyclust.addonreader.resources.custom_blocks"))
|
.setUrls(ClasspathHelper.forPackage("com.cimeyclust.addonreader.resources.custom_blocks"))
|
||||||
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));
|
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));
|
||||||
int count = reflections.getStore().get(TypeAnnotationsScanner.class.getSimpleName()).keySet().size();
|
|
||||||
System.out.println("Number of classes found: " + count);
|
|
||||||
|
|
||||||
// Log super classes of each class in the package
|
// Log super classes of each class in the package
|
||||||
blockReflections.getSubTypesOf(Object.class).forEach(clazz -> System.out.println(clazz + " extends " + clazz.getSuperclass()));
|
blockReflections.getSubTypesOf(Object.class).forEach(clazz -> System.out.println(clazz + " extends " + clazz.getSuperclass()));
|
||||||
@ -55,52 +62,57 @@ public class Plugin extends PluginBase {
|
|||||||
Set<Class<? extends CustomBlock>> blocks = blockReflections.getSubTypesOf(Object.class).stream()
|
Set<Class<? extends CustomBlock>> blocks = blockReflections.getSubTypesOf(Object.class).stream()
|
||||||
.filter(clazz -> clazz.getSuperclass() == CustomBlock.class)
|
.filter(clazz -> clazz.getSuperclass() == CustomBlock.class)
|
||||||
.map(clazz -> (Class<? extends CustomBlock>) clazz)
|
.map(clazz -> (Class<? extends CustomBlock>) clazz)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());*/
|
||||||
|
|
||||||
for (Class<? extends CustomBlock> clazz : blocks) {
|
|
||||||
System.out.println("§aLoading custom block " + clazz + "...");
|
|
||||||
|
for (String blockName : blockNames) {
|
||||||
|
System.out.println("§aLoading custom block " + blockName + "...");
|
||||||
try {
|
try {
|
||||||
|
Class<? extends CustomBlock> clazz = Class.forName("com.cimeyclust.addonreader.resources.custom_blocks." + blockName).asSubclass(CustomBlock.class);
|
||||||
Block.registerCustomBlock(Collections.singletonList(clazz)).assertOK();
|
Block.registerCustomBlock(Collections.singletonList(clazz)).assertOK();
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register Items
|
// Register Items
|
||||||
Reflections itemReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_items");
|
// Reflections itemReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_items");
|
||||||
// Log super classes of each class in the package
|
// Log super classes of each class in the package
|
||||||
itemReflections.getSubTypesOf(Object.class).forEach(clazz -> System.out.println(clazz + " extends " + clazz.getSuperclass()));
|
// itemReflections.getSubTypesOf(Object.class).forEach(clazz -> System.out.println(clazz + " extends " + clazz.getSuperclass()));
|
||||||
|
|
||||||
Set<Class<? extends CustomItem>> items = itemReflections.getSubTypesOf(Object.class).stream()
|
/*Set<Class<? extends CustomItem>> items = itemReflections.getSubTypesOf(Object.class).stream()
|
||||||
.filter(clazz -> clazz.getSuperclass() == CustomItem.class)
|
.filter(clazz -> clazz.getSuperclass() == CustomItem.class)
|
||||||
.map(clazz -> (Class<? extends CustomItem>) clazz)
|
.map(clazz -> (Class<? extends CustomItem>) clazz)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());*/
|
||||||
|
|
||||||
for (Class<? extends CustomItem> clazz : items) {
|
for (String itemName : itemNames) {
|
||||||
System.out.println("§aLoading custom item " + clazz + "...");
|
System.out.println("§aLoading custom item " + itemName + "...");
|
||||||
try {
|
try {
|
||||||
|
Class<? extends CustomItem> clazz = Class.forName("com.cimeyclust.addonreader.resources.custom_items." + itemName).asSubclass(CustomItem.class);
|
||||||
Item.registerCustomItem(clazz).assertOK();
|
Item.registerCustomItem(clazz).assertOK();
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register Entities
|
// Register Entities
|
||||||
Reflections entityReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_entities");
|
// Reflections entityReflections = new Reflections("com.cimeyclust.addonreader.resources.custom_entities");
|
||||||
// Log super classes of each class in the package
|
// Log super classes of each class in the package
|
||||||
entityReflections.getSubTypesOf(Object.class).forEach(clazz -> System.out.println(clazz + " extends " + clazz.getSuperclass()));
|
// entityReflections.getSubTypesOf(Object.class).forEach(clazz -> System.out.println(clazz + " extends " + clazz.getSuperclass()));
|
||||||
|
|
||||||
Set<Class<? extends Entity>> entities = itemReflections.getSubTypesOf(Object.class).stream()
|
/*Set<Class<? extends Entity>> entities = itemReflections.getSubTypesOf(Object.class).stream()
|
||||||
.filter(clazz -> clazz.getSuperclass() == Entity.class)
|
.filter(clazz -> clazz.getSuperclass() == Entity.class)
|
||||||
.map(clazz -> (Class<? extends Entity>) clazz)
|
.map(clazz -> (Class<? extends Entity>) clazz)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());*/
|
||||||
|
|
||||||
for (Class<? extends Entity> clazz : entities) {
|
for (String entityName : entityNames) {
|
||||||
System.out.println("§aLoading custom entity " + clazz + "...");
|
System.out.println("§aLoading custom entity " + entityName + "...");
|
||||||
try {
|
try {
|
||||||
|
Class<? extends Entity> clazz = Class.forName("com.cimeyclust.addonreader.resources.custom_entities." + entityName).asSubclass(Entity.class);
|
||||||
Entity.registerCustomEntity(new CustomClassEntityProvider(clazz)).assertOK();
|
Entity.registerCustomEntity(new CustomClassEntityProvider(clazz)).assertOK();
|
||||||
entities.add(clazz);
|
this.entities.add(clazz);
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user