Files
src
build.gradle
Code
70 4,821
src/main/java/com/caveworld/CaveWorldPlugin.java
package com.caveworld;
import com.caveworld.commands.CaveCommand;
import com.caveworld.config.ConfigManager;
import com.caveworld.items.CustomItems;
import com.caveworld.items.ItemKeys;
import com.caveworld.listeners.*;
import com.caveworld.mobs.GaiaBossManager;
import com.caveworld.mobs.MobManager;
import com.caveworld.structures.StructureManager;
import com.caveworld.systems.*;
import com.caveworld.world.CaveChunkGenerator;
import com.caveworld.world.CaveWorldManager;
import com.caveworld.world.LayerResolver;
import org.bukkit.*;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.*;
public final class CaveWorldPlugin extends JavaPlugin {
protected ConfigManager cfg;
protected LayerResolver layerResolver;
protected CaveWorldManager caveWorldManager;
protected StructureManager structureManager;
protected EmpowermentSystem empowermentSystem;
protected SoulFireSystem soulFireSystem;
protected OpalGrowthSystem opalGrowthSystem;
protected CrystalUpgradeSystem crystalUpgradeSystem;
protected MobManager mobManager;
protected GaiaBossManager gaiaBossManager;
@Override
public void onEnable() {
saveDefaultConfig();
getDataFolder().mkdirs();
new File(getDataFolder(), "data").mkdirs();
new File(getDataFolder(), "nbt").mkdirs();
// Init static keys & item factories
ItemKeys.init(this);
CustomItems.init(this);
// Core systems
cfg = new ConfigManager(this);
layerResolver = new LayerResolver(cfg);
structureManager = new StructureManager(this);
structureManager.loadStructures();
caveWorldManager = new CaveWorldManager(this);
empowermentSystem = new EmpowermentSystem(this);
soulFireSystem = new SoulFireSystem(this);
opalGrowthSystem = new OpalGrowthSystem(this);
crystalUpgradeSystem= new CrystalUpgradeSystem(this);
mobManager = new MobManager(this);
gaiaBossManager = new GaiaBossManager(this);
// Register recipes
registerRecipes();
// Register listeners
var pm = getServer().getPluginManager();
pm.registerEvents(new ItemUseListener(this), this);
pm.registerEvents(new BlockListener(this), this);
pm.registerEvents(new MobListener(this), this);
pm.registerEvents(new PlayerListener(this), this);
pm.registerEvents(new EntityListener(this), this);
pm.registerEvents(new ChunkListener(this), this);
// Register commands
var caveCmd = new CaveCommand(this);
getCommand("cave").setExecutor(caveCmd);
getCommand("cave").setTabCompleter(caveCmd);
// Extract resource pack
extractResourcePack();
getLogger().info("ยงaCaveWorld enabled โ 3 layers of adventure await!");
}
@Override
public void onDisable() {
getLogger().info("CaveWorld disabled.");
}
@Override
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
return new CaveChunkGenerator(cfg, this);
}
protected void registerRecipes() {
// Petrified Wood Scrap โ Opal Block (9 opals shaped)
NamespacedKey opalBlockKey = new NamespacedKey(this, "opal_block");
ShapedRecipe opalBlock = new ShapedRecipe(opalBlockKey, CustomItems.opalBlock());
opalBlock.shape("OOO", "OOO", "OOO");
opalBlock.setIngredient('O', Material.AMETHYST_SHARD);
getServer().addRecipe(opalBlock);
// Crystal: 6 amethyst_shard (pure+) in left two columns + 3 nether_brick in right column
// Validated in PrepareItemCraftEvent to check actual purity
NamespacedKey crystalKey = new NamespacedKey(this, "crystal");
ShapedRecipe crystalRecipe = new ShapedRecipe(crystalKey, CustomItems.crystal());
crystalRecipe.shape("OOR", "OOR", "OOR");
crystalRecipe.setIngredient('O', Material.AMETHYST_SHARD);
crystalRecipe.setIngredient('R', Material.NETHER_BRICK);
getServer().addRecipe(crystalRecipe);
// Petrification Amulet: 8 phantom_membrane around center totem
NamespacedKey amuletKey = new NamespacedKey(this, "petrification_amulet");
ShapedRecipe amulet = new ShapedRecipe(amuletKey, CustomItems.petrificationAmulet());
amulet.shape("SSS", "STS", "SSS");
amulet.setIngredient('S', Material.PHANTOM_MEMBRANE);
amulet.setIngredient('T', Material.TOTEM_OF_UNDYING);
getServer().addRecipe(amulet);
// Opal Prism: opal block center, pure AMETHYST_SHARD NSEW, diamond corners
NamespacedKey prismKey = new NamespacedKey(this, "opal_prism");
ShapedRecipe prism = new ShapedRecipe(prismKey, CustomItems.opalPrism());
prism.shape("DPD", "PBP", "DPD");
prism.setIngredient('D', Material.DIAMOND);
prism.setIngredient('P', Material.AMETHYST_SHARD);
prism.setIngredient('B', Material.AMETHYST_BLOCK);
getServer().addRecipe(prism);
}
protected void extractResourcePack() {
// Copy the resource pack directory from jar to plugin folder
File packDir = new File(getDataFolder(), "resourcepack");
if (packDir.exists()) return; // already extracted
packDir.mkdirs();
String[] packFiles = {
"pack.mcmeta",
"assets/minecraft/items/amethyst_shard.json",
"assets/minecraft/items/coal.json",
"assets/minecraft/items/phantom_membrane.json",
"assets/minecraft/items/totem_of_undying.json",
"assets/minecraft/items/blaze_rod.json",
"assets/minecraft/items/golden_helmet.json",
"assets/minecraft/items/nether_star.json",
"assets/minecraft/items/nether_brick.json",
"assets/minecraft/items/diamond.json",
"assets/minecraft/items/netherite_upgrade_smithing_template.json"
};
for (String packFile : packFiles) {
String resourcePath = "pack/" + packFile;
File dest = new File(packDir, packFile.replace("/", File.separator));
dest.getParentFile().mkdirs();
try (InputStream in = getResource(resourcePath)) {
if (in != null && !dest.exists()) {
try (OutputStream out = new FileOutputStream(dest)) {
in.transferTo(out);
}
}
} catch (IOException e) {
getLogger().warning("Could not extract pack file: " + packFile);
}
}
getLogger().info("Resource pack extracted to plugins/CaveWorld/resourcepack/");
getLogger().info("Zip it and host it as a server resource pack (optional).");
}
// โโโ Getters โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
public ConfigManager getCfg() { return cfg; }
public LayerResolver getLayerResolver() { return layerResolver; }
public CaveWorldManager getCaveWorldManager() { return caveWorldManager; }
public StructureManager getStructureManager() { return structureManager; }
public EmpowermentSystem getEmpowermentSystem() { return empowermentSystem; }
public SoulFireSystem getSoulFireSystem() { return soulFireSystem; }
public OpalGrowthSystem getOpalGrowthSystem() { return opalGrowthSystem; }
public CrystalUpgradeSystem getCrystalUpgradeSystem() { return crystalUpgradeSystem; }
public MobManager getMobManager() { return mobManager; }
public GaiaBossManager getGaiaBossManager() { return gaiaBossManager; }
}