Skip to content

Commit eb5433e

Browse files
committed
feat: enhance AutoRegister annotation and refactor CustomItemManager for improved initialization
1 parent c8acdbb commit eb5433e

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/com/github/pinont/singularitylib/api/annotation/AutoRegister.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.github.pinont.singularitylib.api.annotation;
22

3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Target;
5+
36
/**
47
* Annotation to mark classes for automatic registration by the plugin.
58
* This annotation is used to mark classes that need to be registered during the plugin's startup process.
@@ -10,6 +13,7 @@
1013
* It should only be used when the class extends {@code CustomItem}, {@code SimpleCommand}, or {@code Listener}.
1114
*/
1215

16+
@Target({ElementType.TYPE})
1317
public @interface AutoRegister {
1418
/**
1519
* Indicates that the annotated class should be automatically registered by the plugin.

src/main/java/com/github/pinont/singularitylib/api/manager/CustomItemManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class CustomItemManager implements SimpleCommand {
3737
* Used when the dev tool plugin is present to provide additional
3838
* development and debugging features for custom items.
3939
*/
40-
private final CItemManager customItemManager = new CItemManager();
40+
private CItemManager customItemManager;
4141

4242
/**
4343
* Default constructor for CustomItemManager.
@@ -73,7 +73,7 @@ public List<CustomItem> getCustomItems() {
7373
public void register(List<CustomItem> item) {
7474
if (item.isEmpty()) return;
7575
sendConsoleMessage("Registering " + item.size() + " custom items");
76-
if (getInstance().getServer().getPluginManager().getPlugin("SingularityDevTool") != null) {
76+
if (Common.plugin != null) {
7777
registerAllItems(item, true);
7878
}
7979
registerAllItems(item);
@@ -104,6 +104,9 @@ private void registerAllItems(List<CustomItem> items) {
104104
* @param forDevTool whether to register items with the development tool
105105
*/
106106
private void registerAllItems(List<CustomItem> items, boolean forDevTool) {
107+
if (forDevTool) {
108+
customItemManager = new CItemManager();
109+
}
107110
for (CustomItem customItem : items) {
108111
customItems.add(customItem);
109112
if (forDevTool) {

src/main/java/com/github/pinont/singularitylib/plugin/register/Register.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.pinont.singularitylib.plugin.register;
22

3-
import com.github.pinont.devtool.api.CItemManager;
43
import com.github.pinont.singularitylib.api.annotation.AutoRegister;
54
import com.github.pinont.singularitylib.api.command.SimpleCommand;
65
import com.github.pinont.singularitylib.api.items.CustomItem;

0 commit comments

Comments
 (0)