Files
src
build.gradle
settings.gradle
Code
8 737
src/main/java/com/kodari/bloodscythe/BloodScythePlugin.java
package com.kodari.bloodscythe;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import java.util.List;
public final class BloodScythePlugin extends JavaPlugin {
private ScytheItems scytheItems;
private ScytheListener scytheListener;
private BukkitTask actionBarTask;
@Override
public void onEnable() {
saveDefaultConfig();
scytheItems = new ScytheItems(this);
scytheListener = new ScytheListener(this, scytheItems);
Bukkit.getPluginManager().registerEvents(scytheListener, this);
ScytheCommand scytheCommand = new ScytheCommand(this, scytheItems);
if (getCommand("scythe") != null) {
getCommand("scythe").setExecutor(scytheCommand);
getCommand("scythe").setTabCompleter(scytheCommand);
}
registerRecipe();
actionBarTask = Bukkit.getScheduler().runTaskTimer(this, scytheListener::updateCooldownHud, 10L, 10L);
}
@Override
public void onDisable() {
if (actionBarTask != null) {
actionBarTask.cancel();
actionBarTask = null;
}
Bukkit.getScheduler().cancelTasks(this);
if (scytheListener != null) {
scytheListener.clearState();
}
}
public ScytheItems getScytheItems() {
return scytheItems;
}
private void registerRecipe() {
if (!getConfig().getBoolean("recipe.enabled", false)) {
return;
}
List<String> shape = getConfig().getStringList("recipe.shape");
if (shape.size() != 3 || shape.stream().anyMatch(row -> row.length() != 3)) {
getLogger().warning("The scythe recipe must have exactly three rows of three characters.");
return;
}
ConfigurationSection ingredients = getConfig().getConfigurationSection("recipe.ingredients");
if (ingredients == null) {
getLogger().warning("The scythe recipe is enabled but recipe.ingredients is missing.");
return;
}
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "soul_reaper_scythe"), scytheItems.createScythe());
recipe.shape(shape.toArray(new String[0]));
for (String key : ingredients.getKeys(false)) {
if (key.length() != 1 || key.charAt(0) == ' ') {
getLogger().warning("Ignoring invalid scythe recipe ingredient key: " + key);
continue;
}
String materialName = ingredients.getString(key, "");
Material material = XMaterial.matchXMaterial(materialName)
.map(XMaterial::parseMaterial)
.orElse(null);
if (material == null) {
getLogger().warning("Ignoring unknown scythe recipe material: " + materialName);
continue;
}
recipe.setIngredient(key.charAt(0), material);
}
Bukkit.addRecipe(recipe);
}
}