Files
com
META-INF
config.yml
plugin.yml
pom.xml
Code
6 1,968
com/example/lightpowers/LightPowersPlugin.java
package com.example.lightpowers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.attribute.AttributeModifier.Operation;
import org.bukkit.block.Block;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarFlag;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Snowball;
import org.bukkit.entity.Warden;
import org.bukkit.entity.WitherSkeleton;
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.EntityDamageEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemFlag;
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.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
public final class LightPowersPlugin extends JavaPlugin implements Listener, CommandExecutor, TabCompleter {
private static final UUID REACH_MODIFIER = UUID.fromString("d1c3a9e7-2d5f-4d67-a3fb-8d2d1d5f1e21");
private final Map<UUID, LightType> lights = new ConcurrentHashMap();
private final Map<String, Long> cooldowns = new ConcurrentHashMap();
private final Map<UUID, Integer> hitCounters = new ConcurrentHashMap();
private final Set<UUID> immortals = ConcurrentHashMap.newKeySet();
private final Map<UUID, UUID> golemOwners = new ConcurrentHashMap();
private final Map<UUID, UUID> invasionOwners = new ConcurrentHashMap();
private final Map<UUID, UUID> wardenOwners = new ConcurrentHashMap();
private final Set<UUID> fireballs = ConcurrentHashMap.newKeySet();
private final Set<UUID> cherryPetals = ConcurrentHashMap.newKeySet();
private final Set<UUID> suppressedExplosionDamage = ConcurrentHashMap.newKeySet();
private final Set<UUID> starStrikeFallProtection = ConcurrentHashMap.newKeySet();
private final Map<UUID, Long> abyssalFrozenUntil = new ConcurrentHashMap();
private final Map<String, BossBar> abilityBars = new ConcurrentHashMap();
private final Map<String, UUID> abilityBarOwners = new ConcurrentHashMap();
private final Map<String, Long> abilityActiveUntil = new ConcurrentHashMap();
private final Map<String, Long> abilityCooldownUntil = new ConcurrentHashMap();
private final Map<String, Integer> abilityDurationSeconds = new ConcurrentHashMap();
private final Map<String, Integer> abilityCooldownSeconds = new ConcurrentHashMap();
private final Map<String, String> abilityBarNames = new ConcurrentHashMap();
private NamespacedKey starCrusherKey;
private NamespacedKey sculkCleaverKey;
private NamespacedKey abyssalBladeKey;
private boolean started;
private static final int ABYSSAL_BLADE_TEXTURE_ID = 42001;
public void onEnable() {
this.starCrusherKey = new NamespacedKey(this, "star_crusher");
this.sculkCleaverKey = new NamespacedKey(this, "sculk_cleaver");
this.abyssalBladeKey = new NamespacedKey(this, "abyssal_blade");
this.saveDefaultConfig();
this.loadLights();
this.getServer().getPluginManager().registerEvents(this, this);
this.registerCommand("light");
this.registerCommand("trust");
this.registerCommand("starcrusher");
this.registerCommand("sculkcleaver");
this.registerCommand("abyssalblade");
this.startPlugin();
this.getLogger().info("Light Powers enabled with " + LightType.values().length + " Lights.");
this.getLogger().info("Light Powers is active. New players receive a random Light on first join.");
}
private void startPlugin() {
if (!this.started) {
this.started = true;
this.getServer().getScheduler().runTaskTimer(this, this::applyPassives, 20L, 20L);
this.getServer().getScheduler().runTaskTimer(this, this::directGolems, 20L, 10L);
this.getServer().getScheduler().runTaskTimer(this, this::directInvasions, 20L, 10L);
this.getServer().getScheduler().runTaskTimer(this, this::directWardens, 20L, 10L);
this.getServer().getScheduler().runTaskTimer(this, this::trailFireballs, 1L, 1L);
this.getServer().getScheduler().runTaskTimer(this, this::trailCherryPetals, 1L, 1L);
this.getServer().getScheduler().runTaskTimer(this, this::updateAbilityBars, 1L, 1L);
}
}
private void registerCommand(String var1) {
PluginCommand var2 = this.getCommand(var1);
if (var2 != null) {
var2.setExecutor(this);
var2.setTabCompleter(this);
}
}
public void onDisable() {
for(BossBar var2 : this.abilityBars.values()) {
var2.removeAll();
}
for(UUID var5 : this.wardenOwners.keySet()) {
Entity var3 = Bukkit.getEntity(var5);
if (var3 != null && var3.isValid()) {
var3.remove();
}
}
this.abilityBars.clear();
this.wardenOwners.clear();
this.suppressedExplosionDamage.clear();
this.starStrikeFallProtection.clear();
this.abyssalFrozenUntil.clear();
this.saveLights();
}
@EventHandler
public void onFirstJoin(PlayerJoinEvent var1) {
Player var2 = var1.getPlayer();
if (!this.lights.containsKey(var2.getUniqueId())) {
this.assign(var2, LightType.random(), true);
this.rerollAnimation(var2, (LightType)this.lights.get(var2.getUniqueId()));
}
}
@EventHandler
public void onHostileTarget(EntityTargetLivingEntityEvent var1) {
if (this.started) {
UUID var3;
if (var1.getTarget() != null && var1.getTarget().getUniqueId() != null && (var3 = (UUID)this.golemOwners.get(var1.getEntity().getUniqueId())) != null && var1.getTarget().getUniqueId().equals(var3)) {
var1.setCancelled(true);
} else {
UUID var4 = (UUID)this.invasionOwners.get(var1.getEntity().getUniqueId());
if (var4 == null || var1.getTarget() == null || !var1.getTarget().getUniqueId().equals(var4) && !this.isTrusted((UUID)var4, var1.getTarget())) {
UUID var5 = (UUID)this.wardenOwners.get(var1.getEntity().getUniqueId());
if (var5 == null || var1.getTarget() == null || !var1.getTarget().getUniqueId().equals(var5) && !this.isTrusted((UUID)var5, var1.getTarget())) {
LivingEntity var6 = var1.getTarget();
if (var6 instanceof Player) {
Player var2 = (Player)var6;
if (!(var1.getEntity() instanceof Player)) {
if (this.lights.get(var2.getUniqueId()) == LightType.MOON) {
var1.setCancelled(true);
}
return;
}
}
} else {
var1.setCancelled(true);
}
} else {
var1.setCancelled(true);