From 1cd8f4710322440812d119d0f86804c74df0f0d4 Mon Sep 17 00:00:00 2001 From: Esoteric Enderman <90862990+EsotericEnderman@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:15:00 +0100 Subject: [PATCH] Simplify custom feature constructors --- .../plugins/template/custom/items/AbstractCustomItem.java | 8 ++++---- .../plugins/template/custom/items/CustomItemManager.java | 7 +++++++ .../custom/multiblocks/AbstractCustomMultiblock.java | 4 ++-- .../custom/multiblocks/CustomMultiblockManager.java | 4 ++++ .../custom/multientities/AbstractCustomMultientity.java | 4 ++-- .../custom/multientities/CustomMultientityManager.java | 8 +++++++- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/AbstractCustomItem.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/AbstractCustomItem.java index 834227be..d4db73f3 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/AbstractCustomItem.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/AbstractCustomItem.java @@ -7,18 +7,18 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; -import org.esoteric.minecraft.plugins.template.TemplatePaperPlugin; import org.checkerframework.checker.nullness.qual.NonNull; +import org.esoteric.minecraft.plugins.template.TemplatePaperPlugin; public abstract class AbstractCustomItem implements Listener { - protected final TemplatePaperPlugin plugin; + private final TemplatePaperPlugin plugin; private final CustomItem itemId; private final Material material; - public AbstractCustomItem(TemplatePaperPlugin plugin, CustomItemManager customItemManager, CustomItem itemId, Material material) { - this.plugin = plugin; + public AbstractCustomItem(CustomItemManager customItemManager, CustomItem itemId, Material material) { + this.plugin = customItemManager.getPlugin(); this.itemId = itemId; this.material = material; diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItemManager.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItemManager.java index 169b8a67..6fbdc699 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItemManager.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItemManager.java @@ -9,9 +9,16 @@ public class CustomItemManager { + private final TemplatePaperPlugin plugin; + private final Map customItemMap = new HashMap<>(); + public TemplatePaperPlugin getPlugin() { + return plugin; + } + public CustomItemManager(TemplatePaperPlugin plugin) { + this.plugin = plugin; } public void addCustomItem(CustomItem itemId, AbstractCustomItem customItem) { diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/multiblocks/AbstractCustomMultiblock.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/multiblocks/AbstractCustomMultiblock.java index 3a21ad1a..3df62b43 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/multiblocks/AbstractCustomMultiblock.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/custom/multiblocks/AbstractCustomMultiblock.java @@ -25,8 +25,8 @@ public void addMultiblocks(List> addedMultiblocks) { multiblocks.addAll(addedMultiblocks); } - public AbstractCustomMultiblock(TemplatePaperPlugin plugin, CustomMultiblockManager customMultiblockManager, CustomMultiblock multiblockId) { - this.plugin = plugin; + public AbstractCustomMultiblock(CustomMultiblockManager customMultiblockManager, CustomMultiblock multiblockId) { + this.plugin = customMultiblockManager.getPlugin(); Bukkit.getPluginManager().registerEvents(this, plugin); diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/multiblocks/CustomMultiblockManager.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/multiblocks/CustomMultiblockManager.java index 4ab7d8f8..ed5abbf1 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/multiblocks/CustomMultiblockManager.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/custom/multiblocks/CustomMultiblockManager.java @@ -30,6 +30,10 @@ public class CustomMultiblockManager { private final Map customMultiblockMap = new HashMap<>(); + public TemplatePaperPlugin getPlugin() { + return plugin; + } + public CustomMultiblockManager(TemplatePaperPlugin plugin) { this.plugin = plugin; diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/multientities/AbstractCustomMultientity.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/multientities/AbstractCustomMultientity.java index 6ceb32bc..9b455b7f 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/multientities/AbstractCustomMultientity.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/custom/multientities/AbstractCustomMultientity.java @@ -16,8 +16,8 @@ public abstract class AbstractCustomMultientity implements Lis private final CustomMultientity entityId; - protected AbstractCustomMultientity(TemplatePaperPlugin plugin, CustomMultientityManager customMultientityManager, CustomMultientity entityId) { - this.plugin = plugin; + protected AbstractCustomMultientity(CustomMultientityManager customMultientityManager, CustomMultientity entityId) { + this.plugin = customMultientityManager.getPlugin(); this.entityId = entityId; diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/multientities/CustomMultientityManager.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/multientities/CustomMultientityManager.java index 88dbb312..1d740a4f 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/multientities/CustomMultientityManager.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/custom/multientities/CustomMultientityManager.java @@ -11,10 +11,16 @@ public class CustomMultientityManager { + private final TemplatePaperPlugin plugin; + private final Map> customMultientityMap = new HashMap<>(); - public CustomMultientityManager(TemplatePaperPlugin plugin) { + public TemplatePaperPlugin getPlugin() { + return plugin; + } + public CustomMultientityManager(TemplatePaperPlugin plugin) { + this.plugin = plugin; } public void addCustomEntity(CustomMultientity itemId, AbstractCustomMultientity customMultientity) {