Files
src
build.gradle
settings.gradle
Code
5 244
src/main/java/com/kodari/angelicmace/AngelicMacePlugin.java
package com.kodari.angelicmace;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public final class AngelicMacePlugin extends JavaPlugin {
private static final long COOLDOWN_MILLIS = 180_000L;
private final Map<UUID, Long> healCooldowns = new HashMap<>();
private final Map<UUID, Long> doubleJumpCooldowns = new HashMap<>();
private NamespacedKey maceKey;
@Override
public void onEnable() {
maceKey = new NamespacedKey(this, "angelic_mace");
AngelicMaceCommand command = new AngelicMaceCommand(this);
getCommand("angelic1").setExecutor(command);
getCommand("angelic").setExecutor(command);
}
public ItemStack createAngelicMace() {
ItemStack mace = XMaterial.matchXMaterial("MACE")
.map(XMaterial::parseItem)
.orElse(null);
if (mace == null) {
mace = XMaterial.matchXMaterial("DIAMOND_SWORD")
.map(XMaterial::parseItem)
.orElseThrow(() -> new IllegalStateException("No suitable item material is available."));
}
ItemMeta meta = mace.getItemMeta();
meta.setDisplayName(ChatColor.AQUA + "✦ " + ChatColor.WHITE + "Angelic Mace");
meta.setLore(Arrays.asList(
ChatColor.GRAY + "A weapon blessed by the heavens.",
"",
ChatColor.GREEN + "Healing: " + ChatColor.WHITE + "/angelic1",
ChatColor.YELLOW + "Double jump: " + ChatColor.WHITE + "/angelic 2"
));
meta.getPersistentDataContainer().set(maceKey, PersistentDataType.BYTE, (byte) 1);
mace.setItemMeta(meta);
return mace;
}
public boolean isAngelicMace(ItemStack item) {
if (item == null || !item.hasItemMeta()) {
return false;
}
ItemMeta meta = item.getItemMeta();
return meta.getPersistentDataContainer().has(maceKey, PersistentDataType.BYTE);
}
public void useHealingAbility(Player player) {
if (!isHoldingMace(player)) {
player.sendMessage(ChatColor.RED + "You must be holding the Angelic Mace.");
return;
}
if (!checkCooldown(player, healCooldowns)) {
return;
}
AttributeInstance maxHealth = player.getAttribute(
com.cryptomorin.xseries.XAttribute.of("max_health").map(attribute -> attribute.get()).orElse(null)
);
double health = maxHealth == null ? 20.0D : maxHealth.getValue();
player.setHealth(health);
player.setFoodLevel(20);
player.setSaturation(20.0F);
healCooldowns.put(player.getUniqueId(), System.currentTimeMillis() + COOLDOWN_MILLIS);
player.sendMessage(ChatColor.AQUA + "The Angelic Mace has restored your health.");
XSound.matchXSound("ENTITY_PLAYER_LEVELUP").ifPresent(sound -> sound.play(player));
XParticle.of("HEART").ifPresent(particle -> player.getWorld().spawnParticle(
particle.get(), player.getLocation().add(0.0D, 1.0D, 0.0D), 12, 0.5D, 0.5D, 0.5D, 0.05D));
}
public void useDoubleJumpAbility(Player player) {
if (!isHoldingMace(player)) {
player.sendMessage(ChatColor.RED + "You must be holding the Angelic Mace.");
return;
}
if (!checkCooldown(player, doubleJumpCooldowns)) {
return;
}
Vector velocity = player.getLocation().getDirection().normalize().multiply(1.25D);
velocity.setY(1.0D);
player.setVelocity(velocity);
doubleJumpCooldowns.put(player.getUniqueId(), System.currentTimeMillis() + COOLDOWN_MILLIS);
player.sendMessage(ChatColor.AQUA + "The Angelic Mace launched you into the air.");
XSound.matchXSound("ENTITY_PHANTOM_FLAP").ifPresent(sound -> sound.play(player));
XParticle.of("CLOUD").ifPresent(particle -> player.getWorld().spawnParticle(
particle.get(), player.getLocation(), 18, 0.4D, 0.2D, 0.4D, 0.02D));
}
private boolean isHoldingMace(Player player) {
return isAngelicMace(player.getInventory().getItemInMainHand())
|| isAngelicMace(player.getInventory().getItemInOffHand());
}
private boolean checkCooldown(Player player, Map<UUID, Long> cooldowns) {
long now = System.currentTimeMillis();
long availableAt = cooldowns.getOrDefault(player.getUniqueId(), 0L);
if (availableAt > now) {
long remainingSeconds = (availableAt - now + 999L) / 1000L;
long minutes = remainingSeconds / 60L;
long seconds = remainingSeconds % 60L;
player.sendMessage(ChatColor.RED + "That ability is on cooldown for "
+ minutes + "m " + seconds + "s.");
return false;
}
return true;
}
}