Files
src
build.gradle
Code
3 2,166
src/main/java/com/kodari/vaultmace/VaultMacePlugin.java
package com.kodari.vaultmace;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.particles.XParticle;
import com.cryptomorin.xseries.XPotion;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle.DustOptions;
import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Light;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.ShulkerBullet;
import org.bukkit.entity.Warden;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
public final class VaultMacePlugin extends JavaPlugin implements Listener {
private static final int ITEM_COOLDOWN_TICKS = 120;
private static final long FIRE_MACE_COOLDOWN_MILLIS = 2_000L;
private static final long MACE_ABILITY_COOLDOWN_MILLIS = 20_000L;
private static final long AIR_ABILITY_COOLDOWN_MILLIS = 6_000L;
private static final long EARTH_ABILITY_COOLDOWN_MILLIS = 14_000L;
private static final long EARTH_ROOT_DURATION_MILLIS = 5_000L;
private static final long FIRE_SNEAK_CHARGE_MILLIS = 5_000L;
private static final long WATER_SNEAK_CHARGE_MILLIS = 8_000L;
private static final long FIRE_SNEAK_COOLDOWN_MILLIS = 240_000L;
private static final long WATER_SNEAK_COOLDOWN_MILLIS = 600_000L;
private static final long EARTH_SNEAK_CHARGE_MILLIS = 4_000L;
private static final long AIR_SNEAK_CHARGE_MILLIS = 2_000L;
private static final long EARTH_SNEAK_COOLDOWN_MILLIS = 180_000L;
private static final long AIR_SNEAK_COOLDOWN_MILLIS = 300_000L;
private static final long LIGHT_PROTECTION_MILLIS = 8_000L;
private static final long LIGHT_BLESSING_COOLDOWN_MILLIS = 13_000L;
private static final long DARK_BLESSING_COOLDOWN_MILLIS = 13_000L;
private static final long DARK_SNEAK_CHARGE_MILLIS = 2_000L;
private static final long DARK_SNEAK_COOLDOWN_MILLIS = 180_000L;
private static final long BLACK_HOLE_DURATION_TICKS = 30 * 20L;
private static final long HOLY_POISON_MILLIS = 9_000L;
private static final double MACE_DROP_CHANCE = 0.13;
private static final int MAX_ELEMENTAL_MACES = 3;
private static final Set<String> UNDEAD_TYPES = Set.of("BOGGED", "DROWNED", "HUSK", "PHANTOM",
"SKELETON", "SKELETON_HORSE", "STRAY", "WITHER", "WITHER_SKELETON", "ZOGLIN", "ZOMBIE",
"ZOMBIE_HORSE", "ZOMBIE_VILLAGER", "ZOMBIFIED_PIGLIN");
private final Set<String> checkedVaults = new HashSet<>();
private final Map<UUID, Long> fireMaceCooldowns = new HashMap<>();
private final Map<UUID, Long> fireAbilityCooldowns = new HashMap<>();
private final Map<UUID, Long> waterAbilityCooldowns = new HashMap<>();
private final Map<UUID, Long> airAbilityCooldowns = new HashMap<>();
private final Map<UUID, Long> earthAbilityCooldowns = new HashMap<>();
private final Map<UUID, Location> immobilizedTargets = new HashMap<>();
private final Map<UUID, Boolean> immobilizedMobAiStates = new HashMap<>();
private final Map<UUID, Long> fireSneakCharges = new HashMap<>();
private final Map<UUID, Long> waterSneakCharges = new HashMap<>();
private final Map<UUID, Long> earthSneakCharges = new HashMap<>();
private final Map<UUID, Long> airSneakCharges = new HashMap<>();
private final Map<UUID, Long> fireSneakCooldowns = new HashMap<>();
private final Map<UUID, Long> waterSneakCooldowns = new HashMap<>();
private final Map<UUID, Long> earthSneakCooldowns = new HashMap<>();
private final Map<UUID, Long> airSneakCooldowns = new HashMap<>();
private final Map<UUID, Long> lightSneakCharges = new HashMap<>();
private final Map<UUID, Long> lightSneakCooldowns = new HashMap<>();
private final Map<UUID, Long> lightBlessingCooldowns = new HashMap<>();
private final Map<UUID, Long> darkBlessingCooldowns = new HashMap<>();
private final Map<UUID, Long> darkVeilEnds = new HashMap<>();
private final Map<UUID, Long> lightProtectionUntil = new HashMap<>();
private final Map<UUID, Long> darkSneakCharges = new HashMap<>();
private final Map<UUID, Long> darkSneakCooldowns = new HashMap<>();
private final Map<UUID, Map<Block, BlockData>> blackHoleAbsorbedBlocks = new HashMap<>();
private final Map<UUID, LightSource> lightSources = new HashMap<>();
private final Map<UUID, LightMark> lightMarkedTargets = new HashMap<>();
private final Map<UUID, Long> holyPoisonEnds = new HashMap<>();
private final Map<UUID, Long> holyPoisonNextDamage = new HashMap<>();
private final Map<UUID, LivingEntity> holyPoisonTargets = new HashMap<>();
private final Map<UUID, FlightState> temporaryFlights = new HashMap<>();
private final Map<UUID, String> abilityActionbarMessages = new HashMap<>();
private final Map<UUID, Long> modeSwitchActionbarUntil = new HashMap<>();
private final Map<UUID, UUID> trueMaceKillCredits = new HashMap<>();
private final Set<UUID> pendingTrueMaceChoices = ConcurrentHashMap.newKeySet();
private boolean trueElementalCraftReserved;
private NamespacedKey maceTypeKey;
private NamespacedKey fireRecipeKey;
private NamespacedKey waterRecipeKey;
private NamespacedKey earthRecipeKey;
private NamespacedKey airRecipeKey;
private NamespacedKey trueElementalRecipeKey;
private NamespacedKey maceCollectionAdvancementKey;
private NamespacedKey craftMaceAdvancementKey;
private NamespacedKey obtainFireMaceAdvancementKey;
private NamespacedKey obtainWaterMaceAdvancementKey;
private NamespacedKey obtainEarthMaceAdvancementKey;
private NamespacedKey obtainAirMaceAdvancementKey;
private NamespacedKey maceGrandmasterAdvancementKey;
private NamespacedKey fireMaceOwnedKey;
private NamespacedKey waterMaceOwnedKey;
private NamespacedKey earthMaceOwnedKey;
private NamespacedKey airMaceOwnedKey;
private NamespacedKey trueMaceUnlocksKey;
private NamespacedKey trueMaceSelectedKey;
private NamespacedKey trueMaceUltimateKey;
private NamespacedKey holyPoisonBulletKey;
private NamespacedKey massiveFireballKey;
@Override
public void onEnable() {
maceTypeKey = new NamespacedKey(this, "mace_type");
fireRecipeKey = new NamespacedKey(this, "fire_mace");
waterRecipeKey = new NamespacedKey(this, "water_mace");
earthRecipeKey = new NamespacedKey(this, "earth_mace");
airRecipeKey = new NamespacedKey(this, "air_mace");
trueElementalRecipeKey = new NamespacedKey(this, "true_elemental_mace");
maceCollectionAdvancementKey = new NamespacedKey(this, "mace_achievements/mace");
craftMaceAdvancementKey = new NamespacedKey(this, "mace_achievements/elemental_crafting");
obtainFireMaceAdvancementKey = new NamespacedKey(this, "mace_achievements/fire_mace");
obtainWaterMaceAdvancementKey = new NamespacedKey(this, "mace_achievements/water_mace");
obtainEarthMaceAdvancementKey = new NamespacedKey(this, "mace_achievements/earth_mace");
obtainAirMaceAdvancementKey = new NamespacedKey(this, "mace_achievements/air_mace");
maceGrandmasterAdvancementKey = new NamespacedKey(this, "mace_achievements/grandmaster");
fireMaceOwnedKey = new NamespacedKey(this, "fire_mace_owned");
waterMaceOwnedKey = new NamespacedKey(this, "water_mace_owned");
earthMaceOwnedKey = new NamespacedKey(this, "earth_mace_owned");
airMaceOwnedKey = new NamespacedKey(this, "air_mace_owned");
trueMaceUnlocksKey = new NamespacedKey(this, "true_mace_unlocks");
trueMaceSelectedKey = new NamespacedKey(this, "true_mace_selected");
trueMaceUltimateKey = new NamespacedKey(this, "true_mace_ultimate");
holyPoisonBulletKey = new NamespacedKey(this, "holy_poison_bullet");
massiveFireballKey = new NamespacedKey(this, "massive_fireball");
getServer().getPluginManager().registerEvents(this, this);
registerAdvancements();
registerMaceRecipes();
getServer().getScheduler().runTaskTimer(this, this::applyHeldMaceEffects, 0L, 5L);
getServer().getScheduler().runTaskTimer(this, this::tickHolyPoison, 20L, 20L);
getServer().getScheduler().runTaskTimer(this, this::trackMacePossession, 1L, 1L);
getServer().getScheduler().runTaskTimer(this, this::tickMobMaceAbilities, 20L, 5L);
getServer().getScheduler().runTaskTimer(this, this::tickDarkProtection, 1L, 1L);
}
@Override
public void onDisable() {
for (UUID playerId : new HashSet<>(darkVeilEnds.keySet())) {
Player player = Bukkit.getPlayer(playerId);
if (player != null) {
updateDarkArmor(player, false);
}
}
for (UUID playerId : new HashSet<>(lightSources.keySet())) {
removeLightSource(playerId);