combat indicator
This commit is contained in:
parent
c0245fa014
commit
62f036b2af
2 changed files with 63 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package me.unurled.sacredrealms.sr.components.combat;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
import static me.unurled.sacredrealms.sr.utils.SRPlayerUtils.spawnIndicator;
|
||||
import static me.unurled.sacredrealms.sr.utils.SRPlayerUtils.updateActionBar;
|
||||
|
||||
import java.util.Random;
|
||||
|
@ -104,6 +105,8 @@ public class CombatManager extends Manager {
|
|||
// apply damage
|
||||
|
||||
entity.damage(damage);
|
||||
|
||||
spawnIndicator(entity, false, damage);
|
||||
// TODO: check for status effects (apply status effects depending item of damager)
|
||||
}
|
||||
} else if (entity instanceof Player player) {
|
||||
|
@ -156,6 +159,7 @@ public class CombatManager extends Manager {
|
|||
|
||||
// apply damage
|
||||
player.damage(damage);
|
||||
// add an
|
||||
|
||||
SRPlayer player1 = pm.getPlayer(player.getUniqueId());
|
||||
if (player1 != null) {
|
||||
|
@ -166,11 +170,15 @@ public class CombatManager extends Manager {
|
|||
updateActionBar(player, player1);
|
||||
}
|
||||
|
||||
spawnIndicator(player, false, damage);
|
||||
|
||||
// TODO: check for status effects (apply status effects depending item of damager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent e) {}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,17 @@ package me.unurled.sacredrealms.sr.utils;
|
|||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
|
||||
import java.util.List;
|
||||
import me.unurled.sacredrealms.sr.SR;
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import me.unurled.sacredrealms.sr.components.player.SRPlayer;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Display;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TextDisplay;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SRPlayerUtils {
|
||||
|
@ -58,4 +64,53 @@ public class SRPlayerUtils {
|
|||
comp("<red>❤ " + health + "/" + maxHealth + " <blue>❈ " + mana);
|
||||
p.sendActionBar(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="https://github.com/DragonL0508/D-Damage-Indicators/blob/master/src/main/java/me/dragonl/damageIndicators/GlobalListener.java">author</a>
|
||||
*/
|
||||
public static @NotNull TextDisplay spawnIndicator(
|
||||
@NotNull Entity eventEntity, @NotNull Boolean isHeal, double number) {
|
||||
// vector operation
|
||||
Vector location = eventEntity.getLocation().toVector();
|
||||
Vector facingVector = eventEntity.getFacing().getDirection();
|
||||
Vector spawnVector = location.add(facingVector.multiply(0.75));
|
||||
|
||||
// summon entity
|
||||
TextDisplay indicators =
|
||||
eventEntity
|
||||
.getWorld()
|
||||
.spawn(
|
||||
spawnVector.toLocation(eventEntity.getWorld()).add(0, 0.7, 0), TextDisplay.class);
|
||||
String prefix = "<red>-";
|
||||
if (isHeal) prefix = "<green>+";
|
||||
|
||||
indicators.text(comp(prefix + number));
|
||||
indicators.setBillboard(Display.Billboard.CENTER);
|
||||
indicators.setShadowed(true);
|
||||
indicators.setTeleportDuration(2);
|
||||
indicatorAnimation(indicators);
|
||||
|
||||
return indicators;
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="https://github.com/DragonL0508/D-Damage-Indicators/blob/master/src/main/java/me/dragonl/damageIndicators/GlobalListener.java">author</a>
|
||||
*/
|
||||
private static void indicatorAnimation(TextDisplay indicator) {
|
||||
new BukkitRunnable() {
|
||||
int height = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
indicator.teleport(indicator.getLocation().add(0, 0.1, 0));
|
||||
if (height == 15) {
|
||||
indicator.remove();
|
||||
this.cancel();
|
||||
}
|
||||
height++;
|
||||
}
|
||||
}.runTaskTimer(SR.getInstance(), 0, 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue