combat indicator
This commit is contained in:
parent
c0245fa014
commit
62f036b2af
2 changed files with 63 additions and 0 deletions
|
@ -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