Files
src
build.gradle
settings.gradle
Code
6 222
src/main/java/com/example/heavymace/HeavyMacePlugin.java
package com.example.heavymace;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.java.JavaPlugin;
import com.cryptomorin.xseries.XMaterial;
public final class HeavyMacePlugin extends JavaPlugin {
private NamespacedKey maceKey;
@Override
public void onEnable() {
this.maceKey = new NamespacedKey(this, "heavy_mace");
registerRecipe();
getServer().getPluginManager().registerEvents(new HeavyMaceListener(this), this);
}
public NamespacedKey getMaceKey() {
return maceKey;
}
private void registerRecipe() {
ItemStack enchantedGoldenApple = XMaterial.matchXMaterial("ENCHANTED_GOLDEN_APPLE")
.map(XMaterial::parseItem)
.orElseThrow(() -> new IllegalStateException("Enchanted golden apples are unavailable"));
ItemStack heavyCore = XMaterial.matchXMaterial("HEAVY_CORE")
.map(XMaterial::parseItem)
.orElseThrow(() -> new IllegalStateException("Heavy cores are unavailable"));
ItemStack diamondSword = XMaterial.matchXMaterial("DIAMOND_SWORD")
.map(XMaterial::parseItem)
.orElseThrow(() -> new IllegalStateException("Diamond swords are unavailable"));
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "heavy_mace"), HeavyMaceItem.create(this));
recipe.shape("E E", "HHH", "ES E".replace(" ", ""));
recipe.setIngredient('E', new RecipeChoice.ExactChoice(enchantedGoldenApple));
recipe.setIngredient('H', new RecipeChoice.ExactChoice(heavyCore));
recipe.setIngredient('S', new RecipeChoice.ExactChoice(diamondSword));
Bukkit.addRecipe(recipe);
}
}