Files
src
build.gradle
settings.gradle
Code
5 2,163
src/main/java/com/kodari/godspear/GodSpearPlugin.java
package com.kodari.godspear;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.BanList;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
import org.bukkit.SoundCategory;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
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.EntityDamageEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
public final class GodSpearPlugin extends org.bukkit.plugin.java.JavaPlugin implements Listener, CommandExecutor, TabCompleter {
private final Map<UUID, Long> freezeCooldowns = new HashMap<>();
private final Map<UUID, Location> frozenLocations = new HashMap<>();
private final Map<UUID, LivingEntity> frozenEntities = new HashMap<>();
private final Map<UUID, Boolean> previousAiStates = new HashMap<>();
private final Map<UUID, Integer> previousFreezeTicks = new HashMap<>();
private final Map<UUID, Integer> previousMaximumNoDamageTicks = new HashMap<>();
private final Map<UUID, Long> lastAirborneAt = new HashMap<>();
private final Map<UUID, Float> lastAirborneFallDistance = new HashMap<>();
private final Map<UUID, Long> lungeFoodProtectionUntil = new HashMap<>();
private final Map<UUID, BukkitTask> freezeTasks = new HashMap<>();
private BukkitTask auraParticleTask;
private double auraParticleAngle;
private int auraTickCounter;
private NamespacedKey godSpearKey;
private NamespacedKey bloodMaceKey;
private NamespacedKey bloodStrikeKey;
private NamespacedKey windBurstKey;
private NamespacedKey bloodStrikeBookKey;
private NamespacedKey windBurstBookKey;
private NamespacedKey adminStickKey;
private NamespacedKey spearRecipeKey;
private NamespacedKey bloodMaceRecipeKey;
@Override
public void onEnable() {
saveDefaultConfig();
godSpearKey = new NamespacedKey(this, "god_spear");
bloodMaceKey = new NamespacedKey(this, "blood_mace");
bloodStrikeKey = new NamespacedKey(this, "blood_strike_level");
windBurstKey = new NamespacedKey(this, "wind_burst_level");
bloodStrikeBookKey = new NamespacedKey(this, "blood_strike_book_level");
windBurstBookKey = new NamespacedKey(this, "wind_burst_book_level");
adminStickKey = new NamespacedKey(this, "admin_stick");
spearRecipeKey = new NamespacedKey(this, "god_spear_recipe");
bloodMaceRecipeKey = new NamespacedKey(this, "blood_mace_recipe");
registerSpearRecipe();
registerBloodMaceRecipe();
Bukkit.getPluginManager().registerEvents(this, this);
if (getCommand("godspear") != null) {
getCommand("godspear").setExecutor(this);
getCommand("godspear").setTabCompleter(this);
}
auraParticleTask = new BukkitRunnable() {
@Override
public void run() {
if (!getConfig().getBoolean("aura.enabled", true)) {
return;
}
int interval = Math.max(1, getConfig().getInt("aura.interval-ticks", 10));
if (++auraTickCounter < interval) {
return;
}
auraTickCounter = 0;
for (World world : Bukkit.getWorlds()) {
for (LivingEntity entity : world.getLivingEntities()) {
if (!(entity instanceof Player) && !entity.getType().name().equals("MANNEQUIN")) {
continue;
}
if (entity.getEquipment() != null
&& isGodSpear(entity.getEquipment().getItemInMainHand())) {
spawnAuraParticles(entity);
}
}
}
auraParticleAngle += Math.toRadians(getConfig().getDouble("aura.rotation-degrees-per-update", 20.0));
}
}.runTaskTimer(this, 0L, 1L);
}
@Override
public void onDisable() {
if (auraParticleTask != null) {
auraParticleTask.cancel();
}
for (UUID entityId : new HashSet<>(freezeTasks.keySet())) {
endFreeze(entityId);
}
}
@EventHandler
public void onSpearHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player attacker)
|| !(event.getEntity() instanceof LivingEntity target)
|| attacker.equals(target)
|| !isGodSpear(attacker.getInventory().getItemInMainHand())) {
return;
}
if (getConfig().getBoolean("hit-lightning.enabled", true)) {
target.getWorld().strikeLightningEffect(target.getLocation());
}
String criticalSound = getConfig().getString("hit-critical.sound", "entity.player.attack.crit");
if (criticalSound != null && !criticalSound.isEmpty()) {
target.getWorld().playSound(target.getLocation(), criticalSound,
(float) getConfig().getDouble("hit-critical.volume", 1.0),
(float) getConfig().getDouble("hit-critical.pitch", 1.0));
}
if (target instanceof Player blockingTarget && blockingTarget.isBlocking()) {
event.setDamage(DamageModifier.BLOCKING, 0.0);
}
long now = System.currentTimeMillis();
long cooldownMillis = Math.max(0L, Math.round(getConfig().getDouble("freeze.cooldown-seconds", 5.0) * 1000.0));
long availableAt = freezeCooldowns.getOrDefault(attacker.getUniqueId(), 0L);
if (now < availableAt) {
return;
}
freezeCooldowns.put(attacker.getUniqueId(), now + cooldownMillis);
freeze(target);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onAdminStickHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player attacker)
|| !(event.getEntity() instanceof Player target)
|| attacker.equals(target)
|| !attacker.hasPermission("godspear.admin")
|| !isAdminStick(attacker.getInventory().getItemInMainHand())) {
return;
}
event.setCancelled(true);
String mode = getConfig().getString("admin-stick.mode", "kick");
if (mode.equalsIgnoreCase("check")) {
String checkCommand = getConfig().getString("admin-stick.check-command", "check %target%");
if (checkCommand != null && !checkCommand.isBlank()) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checkCommand.replace("%target%", target.getName()));
}
return;
}
String reason = getConfig().getString(mode.equalsIgnoreCase("ban")
? "admin-stick.ban-reason" : "admin-stick.kick-reason", "Удалён администратором.");
if (mode.equalsIgnoreCase("ban")) {
Bukkit.getBanList(BanList.Type.NAME).addBan(target.getName(), reason, null, attacker.getName());