Misc cleanup (thanks @Col-E)

Signed-off-by: SticksDev <tanner@teamhydra.dev>
This commit is contained in:
Tanner Sommers 2023-06-09 21:14:27 -04:00
parent 616c6ea517
commit 98290f1c61
7 changed files with 31 additions and 20 deletions

View File

@ -23,8 +23,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>${java.version}</source> <source>16</source>
<target>${java.version}</target> <target>16</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -8,6 +8,7 @@ import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import redis.clients.jedis.JedisPooled; import redis.clients.jedis.JedisPooled;
@ -159,4 +160,15 @@ public class ManaHandler implements Listener {
setEXPBar(player); 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);
}
} }

View File

@ -49,9 +49,9 @@ public class EarthSpell extends ItemBasedSpell {
} }
} }
if (nearestEntity instanceof LivingEntity) { if (nearestEntity instanceof LivingEntity LE) {
// Damage the nearest entity // Damage the nearest entity
((LivingEntity) nearestEntity).damage(earthSpell.getDamage()); LE.damage(earthSpell.getDamage());
} }
// Cancel the task // Cancel the task

View File

@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
public class LightningSpell extends ItemBasedSpell { public class LightningSpell extends ItemBasedSpell {
public LightningSpell() { 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) { private static void castLightning(Player player, Entity nearestEntity) {
@ -21,8 +21,8 @@ public class LightningSpell extends ItemBasedSpell {
world.strikeLightningEffect(location); world.strikeLightningEffect(location);
if (nearestEntity instanceof LivingEntity) { if (nearestEntity instanceof LivingEntity LE) {
((LivingEntity) nearestEntity).damage(lightningSpell.getDamage()); LE.damage(lightningSpell.getDamage());
} }
} }
} }

View File

@ -45,9 +45,9 @@ public class WaterSpell extends ItemBasedSpell {
} }
} }
if (nearestEntity instanceof LivingEntity) { if (nearestEntity instanceof LivingEntity LE) {
// Damage the nearest entity // Damage the nearest entity
((LivingEntity) nearestEntity).damage(waterSpell.getDamage()); LE.damage(waterSpell.getDamage());
} }
// Cancel the task // Cancel the task

View File

@ -4,9 +4,9 @@ package me.sticksdev.runicspells.structures;
* The base class for spells, only contains a name and a description * The base class for spells, only contains a name and a description
*/ */
public class BaseSpell { public class BaseSpell {
public String name; public final String name;
public String description; public final String description;
public int spellID; public final int spellID;
public int range; public int range;
/** /**

View File

@ -15,6 +15,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.function.BiConsumer; 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<Player, Entity> castHandler) { public ItemBasedSpell(String name, String description, int spellId, int range, String item, int cooldown, int manaCost, int damage, boolean requiresNearbyEntity, BiConsumer<Player, Entity> castHandler) {
super(name, description, range, spellId); super(name, description, range, spellId);
this.name = name;
this.description = description;
this.item = item; this.item = item;
this.cooldown = cooldown; this.cooldown = cooldown;
this.manaCost = manaCost; this.manaCost = manaCost;
this.castHandler = castHandler; this.castHandler = castHandler;
this.damage = damage; this.damage = damage;
this.requiresNearbyEntity = requiresNearbyEntity; this.requiresNearbyEntity = requiresNearbyEntity;
this.range = range;
} }
/** /**
@ -158,11 +156,12 @@ public class ItemBasedSpell extends BaseSpell implements Listener {
*/ */
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
// TODO: Little messy, could clean this up later final ItemStack eventItem = event.getItem();
if (event.getItem() != null && event.getItem().getType() != Material.AIR && final Action eventAction = event.getAction();
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 (eventItem != null && eventItem.getType() != Material.AIR &&
if (event.getItem() != null && event.getItem().getType().toString().equals(item)) { (eventAction == Action.RIGHT_CLICK_AIR || eventAction == Action.LEFT_CLICK_AIR)) {
if (eventItem.getType().toString().equals(item)) {
// Check if they have an active cooldown // Check if they have an active cooldown
Player player = event.getPlayer(); Player player = event.getPlayer();
double cooldown = cooldownHandler.getCooldown(player, this); double cooldown = cooldownHandler.getCooldown(player, this);