9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-21 07:59:28 +00:00

Updated to use UUID's on backend and update entity object on tick

This commit is contained in:
Auxilor
2021-05-20 11:39:35 +01:00
parent 3a480da078
commit a31b0210ab
4 changed files with 26 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ import com.willfp.ecobosses.bosses.tick.tickers.BossBarTicker;
import com.willfp.ecobosses.bosses.tick.tickers.HealthPlaceholderTicker;
import com.willfp.ecobosses.bosses.tick.tickers.TargetTicker;
import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
@@ -25,13 +26,20 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
public class LivingEcoBoss extends PluginDependent {
/**
* The entity.
*/
private final LivingEntity entity;
@Getter
private LivingEntity entity;
/**
* The entity UUID.
*/
private final UUID uuid;
/**
* The boss.
@@ -60,6 +68,7 @@ public class LivingEcoBoss extends PluginDependent {
@NotNull final EcoBoss boss) {
super(plugin);
this.entity = entity;
this.uuid = entity.getUniqueId();
this.boss = boss;
this.onSpawn();
@@ -132,13 +141,9 @@ public class LivingEcoBoss extends PluginDependent {
private void tick(final long tick,
@NotNull final RunnableTask runnable) {
for (BossTicker ticker : tickers) {
ticker.tick(boss, entity, tick);
}
for (Effect effect : effects) {
effect.tick(boss, entity, tick);
}
if (entity.isDead() || Bukkit.getEntity(entity.getUniqueId()) == null || boss.getLivingBoss(entity) == null) {
this.entity = (LivingEntity) Bukkit.getEntity(uuid);
if (entity == null || entity.isDead() || boss.getLivingBoss(entity) == null) {
for (BossTicker ticker : tickers) {
ticker.onDeath(boss, entity, tick);
}
@@ -148,6 +153,13 @@ public class LivingEcoBoss extends PluginDependent {
boss.removeLivingBoss(entity.getUniqueId());
runnable.cancel();
}
for (BossTicker ticker : tickers) {
ticker.tick(boss, entity, tick);
}
for (Effect effect : effects) {
effect.tick(boss, entity, tick);
}
}
/**

View File

@@ -7,6 +7,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
@@ -80,7 +81,7 @@ public abstract class Effect implements BossTicker {
*/
@Override
public void onDeath(@NotNull final EcoBoss boss,
@NotNull final LivingEntity entity,
@Nullable final LivingEntity entity,
final long tick) {
// Override when needed.
}

View File

@@ -3,6 +3,7 @@ package com.willfp.ecobosses.bosses.tick;
import com.willfp.ecobosses.bosses.EcoBoss;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface BossTicker {
/**
@@ -24,7 +25,7 @@ public interface BossTicker {
* @param tick The current tick: counts up from zero.
*/
default void onDeath(@NotNull EcoBoss boss,
@NotNull LivingEntity entity,
@Nullable LivingEntity entity,
long tick) {
// Can be overridden when needed.
}

View File

@@ -9,6 +9,7 @@ import org.bukkit.boss.KeyedBossBar;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class BossBarTicker implements BossTicker {
/**
@@ -51,7 +52,7 @@ public class BossBarTicker implements BossTicker {
@Override
public void onDeath(@NotNull final EcoBoss boss,
@NotNull final LivingEntity entity,
@Nullable final LivingEntity entity,
final long tick) {
bossBar.removeAll();
bossBar.setVisible(false);