mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-21 16:09:24 +00:00
Updated to use UUID's on backend and update entity object on tick
This commit is contained in:
@@ -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.HealthPlaceholderTicker;
|
||||||
import com.willfp.ecobosses.bosses.tick.tickers.TargetTicker;
|
import com.willfp.ecobosses.bosses.tick.tickers.TargetTicker;
|
||||||
import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
|
import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
|
||||||
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
@@ -25,13 +26,20 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
public class LivingEcoBoss extends PluginDependent {
|
public class LivingEcoBoss extends PluginDependent {
|
||||||
/**
|
/**
|
||||||
* The entity.
|
* The entity.
|
||||||
*/
|
*/
|
||||||
private final LivingEntity entity;
|
@Getter
|
||||||
|
private LivingEntity entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entity UUID.
|
||||||
|
*/
|
||||||
|
private final UUID uuid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The boss.
|
* The boss.
|
||||||
@@ -60,6 +68,7 @@ public class LivingEcoBoss extends PluginDependent {
|
|||||||
@NotNull final EcoBoss boss) {
|
@NotNull final EcoBoss boss) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
|
this.uuid = entity.getUniqueId();
|
||||||
this.boss = boss;
|
this.boss = boss;
|
||||||
|
|
||||||
this.onSpawn();
|
this.onSpawn();
|
||||||
@@ -132,13 +141,9 @@ public class LivingEcoBoss extends PluginDependent {
|
|||||||
|
|
||||||
private void tick(final long tick,
|
private void tick(final long tick,
|
||||||
@NotNull final RunnableTask runnable) {
|
@NotNull final RunnableTask runnable) {
|
||||||
for (BossTicker ticker : tickers) {
|
this.entity = (LivingEntity) Bukkit.getEntity(uuid);
|
||||||
ticker.tick(boss, entity, tick);
|
|
||||||
}
|
if (entity == null || entity.isDead() || boss.getLivingBoss(entity) == null) {
|
||||||
for (Effect effect : effects) {
|
|
||||||
effect.tick(boss, entity, tick);
|
|
||||||
}
|
|
||||||
if (entity.isDead() || Bukkit.getEntity(entity.getUniqueId()) == null || boss.getLivingBoss(entity) == null) {
|
|
||||||
for (BossTicker ticker : tickers) {
|
for (BossTicker ticker : tickers) {
|
||||||
ticker.onDeath(boss, entity, tick);
|
ticker.onDeath(boss, entity, tick);
|
||||||
}
|
}
|
||||||
@@ -148,6 +153,13 @@ public class LivingEcoBoss extends PluginDependent {
|
|||||||
boss.removeLivingBoss(entity.getUniqueId());
|
boss.removeLivingBoss(entity.getUniqueId());
|
||||||
runnable.cancel();
|
runnable.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (BossTicker ticker : tickers) {
|
||||||
|
ticker.tick(boss, entity, tick);
|
||||||
|
}
|
||||||
|
for (Effect effect : effects) {
|
||||||
|
effect.tick(boss, entity, tick);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -80,7 +81,7 @@ public abstract class Effect implements BossTicker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onDeath(@NotNull final EcoBoss boss,
|
public void onDeath(@NotNull final EcoBoss boss,
|
||||||
@NotNull final LivingEntity entity,
|
@Nullable final LivingEntity entity,
|
||||||
final long tick) {
|
final long tick) {
|
||||||
// Override when needed.
|
// Override when needed.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.willfp.ecobosses.bosses.tick;
|
|||||||
import com.willfp.ecobosses.bosses.EcoBoss;
|
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public interface BossTicker {
|
public interface BossTicker {
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +25,7 @@ public interface BossTicker {
|
|||||||
* @param tick The current tick: counts up from zero.
|
* @param tick The current tick: counts up from zero.
|
||||||
*/
|
*/
|
||||||
default void onDeath(@NotNull EcoBoss boss,
|
default void onDeath(@NotNull EcoBoss boss,
|
||||||
@NotNull LivingEntity entity,
|
@Nullable LivingEntity entity,
|
||||||
long tick) {
|
long tick) {
|
||||||
// Can be overridden when needed.
|
// Can be overridden when needed.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.bukkit.boss.KeyedBossBar;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class BossBarTicker implements BossTicker {
|
public class BossBarTicker implements BossTicker {
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +52,7 @@ public class BossBarTicker implements BossTicker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeath(@NotNull final EcoBoss boss,
|
public void onDeath(@NotNull final EcoBoss boss,
|
||||||
@NotNull final LivingEntity entity,
|
@Nullable final LivingEntity entity,
|
||||||
final long tick) {
|
final long tick) {
|
||||||
bossBar.removeAll();
|
bossBar.removeAll();
|
||||||
bossBar.setVisible(false);
|
bossBar.setVisible(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user