Skip to content

Commit

Permalink
Add a way to add custom multiblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
esotericenderman committed Aug 12, 2024
1 parent 18ebfdf commit 7a419f2
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,6 +71,10 @@ public NamespacedKey getCustomEntityIdKey() {
return customEntityIdKey;
}

public String getCustomMultiblockIdKey() {
return customMultiblockIdKey;
}

@Override
public void onEnable() {
getDataFolder().mkdir();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Block> generateCustomMultiblock(Location placeLocation);

public List<Block> getCustomMultiblock(Location placeLocation) {
List<Block> multiblock = generateCustomMultiblock(placeLocation);

for (Block block : multiblock) {
block.setMetadata(plugin.getCustomMultiblockIdKey(), new FixedMetadataValue(plugin, multiblockId.name()));
}

return multiblock;
}

public boolean isBlock(Block block) {
List<MetadataValue> values = block.getMetadata(plugin.getCustomMultiblockIdKey());

if (values.size() == 0) {
return false;
}

return multiblockId.name().equals(values.get(0).asString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.slqmy.template_paper_plugin.custom_multiblock;

public enum CustomMultiblock {

}
Original file line number Diff line number Diff line change
@@ -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<CustomMultiblock, AbstractCustomMultiblock> 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);
}
}

0 comments on commit 7a419f2

Please sign in to comment.