diff --git a/src/main/java/net/slqmy/template_paper_plugin/TemplatePaperPlugin.java b/src/main/java/net/slqmy/template_paper_plugin/TemplatePaperPlugin.java index 44127ae5..8e6ec62a 100644 --- a/src/main/java/net/slqmy/template_paper_plugin/TemplatePaperPlugin.java +++ b/src/main/java/net/slqmy/template_paper_plugin/TemplatePaperPlugin.java @@ -33,6 +33,7 @@ public final class TemplatePaperPlugin extends JavaPlugin { private final NamespacedKey customItemIdKey = new NamespacedKey(this, "custom_item_id"); private final NamespacedKey customEntityIdKey = new NamespacedKey(this, "custom_entity_id"); + private final String customMultiblockIdKey = "custom_multiblock_id"; public FileManager getFileManager() { return fileManager; @@ -70,6 +71,10 @@ public NamespacedKey getCustomEntityIdKey() { return customEntityIdKey; } + public String getCustomMultiblockIdKey() { + return customMultiblockIdKey; + } + @Override public void onEnable() { getDataFolder().mkdir(); diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/AbstractCustomMultiblock.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/AbstractCustomMultiblock.java new file mode 100644 index 00000000..4360bc9c --- /dev/null +++ b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/AbstractCustomMultiblock.java @@ -0,0 +1,51 @@ +package net.slqmy.template_paper_plugin.custom_multiblock; + +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.event.Listener; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.metadata.MetadataValue; + +import net.slqmy.template_paper_plugin.TemplatePaperPlugin; + +public abstract class AbstractCustomMultiblock implements Listener { + + private final TemplatePaperPlugin plugin; + + private final CustomMultiblock multiblockId; + + public AbstractCustomMultiblock(TemplatePaperPlugin plugin, CustomMultiblockManager customMultiblockManager, CustomMultiblock multiblockId) { + this.plugin = plugin; + + this.multiblockId = multiblockId; + + Bukkit.getPluginManager().registerEvents(this, plugin); + + customMultiblockManager.addCustomMultiblock(multiblockId, this); + } + + protected abstract List generateCustomMultiblock(Location placeLocation); + + public List getCustomMultiblock(Location placeLocation) { + List multiblock = generateCustomMultiblock(placeLocation); + + for (Block block : multiblock) { + block.setMetadata(plugin.getCustomMultiblockIdKey(), new FixedMetadataValue(plugin, multiblockId.name())); + } + + return multiblock; + } + + public boolean isBlock(Block block) { + List values = block.getMetadata(plugin.getCustomMultiblockIdKey()); + + if (values.size() == 0) { + return false; + } + + return multiblockId.name().equals(values.get(0).asString()); + } +} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblock.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblock.java new file mode 100644 index 00000000..e4ec7d16 --- /dev/null +++ b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblock.java @@ -0,0 +1,5 @@ +package net.slqmy.template_paper_plugin.custom_multiblock; + +public enum CustomMultiblock { + +} diff --git a/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblockManager.java b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblockManager.java new file mode 100644 index 00000000..40430f99 --- /dev/null +++ b/src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblockManager.java @@ -0,0 +1,33 @@ +package net.slqmy.template_paper_plugin.custom_multiblock; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; + +import net.slqmy.template_paper_plugin.custom_multiblock.AbstractCustomMultiblock; +import net.slqmy.template_paper_plugin.custom_multiblock.CustomMultiblock; +import net.slqmy.template_paper_plugin.TemplatePaperPlugin; + +public class CustomMultiblockManager { + + private final TemplatePaperPlugin plugin; + + private final Map customMultiblockMap = new HashMap<>(); + + public CustomMultiblockManager(TemplatePaperPlugin plugin) { + this.plugin = plugin; + } + + public void addCustomMultiblock(CustomMultiblock multiblockId, AbstractCustomMultiblock abstractCustomMultiblock) { + customMultiblockMap.put(multiblockId, abstractCustomMultiblock); + } + + public AbstractCustomMultiblock getAbstractCustomMultiblock(CustomMultiblock multiblockId) { + return customMultiblockMap.get(multiblockId); + } + + public void placeCustomMultiblock(CustomMultiblock multiblockId, Location location) { + customMultiblockMap.get(multiblockId).getCustomMultiblock(location); + } +}