From 98290f1c6150be51bf2045b80b740ff1d8b4e3da Mon Sep 17 00:00:00 2001 From: SticksDev Date: Fri, 9 Jun 2023 21:14:27 -0400 Subject: [PATCH] Misc cleanup (thanks @Col-E) Signed-off-by: SticksDev --- pom.xml | 4 ++-- .../runicspells/handlers/ManaHandler.java | 12 ++++++++++++ .../sticksdev/runicspells/spells/EarthSpell.java | 4 ++-- .../runicspells/spells/LightningSpell.java | 6 +++--- .../sticksdev/runicspells/spells/WaterSpell.java | 4 ++-- .../runicspells/structures/BaseSpell.java | 6 +++--- .../runicspells/structures/ItemBasedSpell.java | 15 +++++++-------- 7 files changed, 31 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index e595823..50fa086 100644 --- a/pom.xml +++ b/pom.xml @@ -23,8 +23,8 @@ maven-compiler-plugin 3.8.1 - ${java.version} - ${java.version} + 16 + 16 diff --git a/src/main/java/me/sticksdev/runicspells/handlers/ManaHandler.java b/src/main/java/me/sticksdev/runicspells/handlers/ManaHandler.java index 21de4db..fb1cb3f 100644 --- a/src/main/java/me/sticksdev/runicspells/handlers/ManaHandler.java +++ b/src/main/java/me/sticksdev/runicspells/handlers/ManaHandler.java @@ -8,6 +8,7 @@ import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scheduler.BukkitRunnable; import redis.clients.jedis.JedisPooled; @@ -159,4 +160,15 @@ public class ManaHandler implements Listener { setEXPBar(player); } } + + /** + * On player death reset the expbar to their current mana + * + * @param event The PlayerDeathEvent + */ + @EventHandler + public void onPlayerDeath(PlayerDeathEvent event) { + Player player = event.getPlayer(); + setEXPBar(player); + } } diff --git a/src/main/java/me/sticksdev/runicspells/spells/EarthSpell.java b/src/main/java/me/sticksdev/runicspells/spells/EarthSpell.java index 046a3d0..ae2519b 100644 --- a/src/main/java/me/sticksdev/runicspells/spells/EarthSpell.java +++ b/src/main/java/me/sticksdev/runicspells/spells/EarthSpell.java @@ -49,9 +49,9 @@ public class EarthSpell extends ItemBasedSpell { } } - if (nearestEntity instanceof LivingEntity) { + if (nearestEntity instanceof LivingEntity LE) { // Damage the nearest entity - ((LivingEntity) nearestEntity).damage(earthSpell.getDamage()); + LE.damage(earthSpell.getDamage()); } // Cancel the task diff --git a/src/main/java/me/sticksdev/runicspells/spells/LightningSpell.java b/src/main/java/me/sticksdev/runicspells/spells/LightningSpell.java index 760a55f..396913d 100644 --- a/src/main/java/me/sticksdev/runicspells/spells/LightningSpell.java +++ b/src/main/java/me/sticksdev/runicspells/spells/LightningSpell.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; public class LightningSpell extends ItemBasedSpell { public LightningSpell() { - super("Lightning", "Strikes lightning at the target", 4, 25, "BLAZE_ROD", 3, 10, 0, true, LightningSpell::castLightning); + super("Lightning", "Strikes lightning at the target", 4, 25, "BLAZE_ROD", 3, 10, 10, true, LightningSpell::castLightning); } private static void castLightning(Player player, Entity nearestEntity) { @@ -21,8 +21,8 @@ public class LightningSpell extends ItemBasedSpell { world.strikeLightningEffect(location); - if (nearestEntity instanceof LivingEntity) { - ((LivingEntity) nearestEntity).damage(lightningSpell.getDamage()); + if (nearestEntity instanceof LivingEntity LE) { + LE.damage(lightningSpell.getDamage()); } } } diff --git a/src/main/java/me/sticksdev/runicspells/spells/WaterSpell.java b/src/main/java/me/sticksdev/runicspells/spells/WaterSpell.java index e3f1db4..9777c5b 100644 --- a/src/main/java/me/sticksdev/runicspells/spells/WaterSpell.java +++ b/src/main/java/me/sticksdev/runicspells/spells/WaterSpell.java @@ -45,9 +45,9 @@ public class WaterSpell extends ItemBasedSpell { } } - if (nearestEntity instanceof LivingEntity) { + if (nearestEntity instanceof LivingEntity LE) { // Damage the nearest entity - ((LivingEntity) nearestEntity).damage(waterSpell.getDamage()); + LE.damage(waterSpell.getDamage()); } // Cancel the task diff --git a/src/main/java/me/sticksdev/runicspells/structures/BaseSpell.java b/src/main/java/me/sticksdev/runicspells/structures/BaseSpell.java index ddf40e6..5064960 100644 --- a/src/main/java/me/sticksdev/runicspells/structures/BaseSpell.java +++ b/src/main/java/me/sticksdev/runicspells/structures/BaseSpell.java @@ -4,9 +4,9 @@ package me.sticksdev.runicspells.structures; * The base class for spells, only contains a name and a description */ public class BaseSpell { - public String name; - public String description; - public int spellID; + public final String name; + public final String description; + public final int spellID; public int range; /** diff --git a/src/main/java/me/sticksdev/runicspells/structures/ItemBasedSpell.java b/src/main/java/me/sticksdev/runicspells/structures/ItemBasedSpell.java index 0d57e47..2c6a448 100644 --- a/src/main/java/me/sticksdev/runicspells/structures/ItemBasedSpell.java +++ b/src/main/java/me/sticksdev/runicspells/structures/ItemBasedSpell.java @@ -15,6 +15,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; import java.util.function.BiConsumer; @@ -50,15 +51,12 @@ public class ItemBasedSpell extends BaseSpell implements Listener { */ public ItemBasedSpell(String name, String description, int spellId, int range, String item, int cooldown, int manaCost, int damage, boolean requiresNearbyEntity, BiConsumer castHandler) { super(name, description, range, spellId); - this.name = name; - this.description = description; this.item = item; this.cooldown = cooldown; this.manaCost = manaCost; this.castHandler = castHandler; this.damage = damage; this.requiresNearbyEntity = requiresNearbyEntity; - this.range = range; } /** @@ -158,11 +156,12 @@ public class ItemBasedSpell extends BaseSpell implements Listener { */ @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - // TODO: Little messy, could clean this up later - if (event.getItem() != null && event.getItem().getType() != Material.AIR && - event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK && - (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR)) { - if (event.getItem() != null && event.getItem().getType().toString().equals(item)) { + final ItemStack eventItem = event.getItem(); + final Action eventAction = event.getAction(); + + if (eventItem != null && eventItem.getType() != Material.AIR && + (eventAction == Action.RIGHT_CLICK_AIR || eventAction == Action.LEFT_CLICK_AIR)) { + if (eventItem.getType().toString().equals(item)) { // Check if they have an active cooldown Player player = event.getPlayer(); double cooldown = cooldownHandler.getCooldown(player, this);