9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-20 15:39:31 +00:00

Added death time ticker

This commit is contained in:
Auxilor
2021-08-13 14:12:47 +01:00
parent b18eb3942a
commit 99de824b04
6 changed files with 71 additions and 18 deletions

View File

@@ -239,6 +239,12 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
@Getter @Getter
private final int autoSpawnInterval; private final int autoSpawnInterval;
/**
* The time to live.
*/
@Getter
private final int timeToLive;
/** /**
* Locations that the boss can auto spawn at. * Locations that the boss can auto spawn at.
*/ */
@@ -277,6 +283,7 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
this.maxHealth = this.getConfig().getInt("max-health"); this.maxHealth = this.getConfig().getInt("max-health");
this.followRange = this.getConfig().getInt("follow-range"); this.followRange = this.getConfig().getInt("follow-range");
this.movementSpeedMultiplier = this.getConfig().getInt("movement-speed"); this.movementSpeedMultiplier = this.getConfig().getInt("movement-speed");
this.timeToLive = this.getConfig().getInt("time-to-live", -1);
// Spawn Totem // Spawn Totem
this.spawnTotemEnabled = this.getConfig().getBool("spawn-totem.enabled"); this.spawnTotemEnabled = this.getConfig().getBool("spawn-totem.enabled");

View File

@@ -8,7 +8,8 @@ import com.willfp.eco.util.StringUtils;
import com.willfp.ecobosses.bosses.effects.Effect; import com.willfp.ecobosses.bosses.effects.Effect;
import com.willfp.ecobosses.bosses.tick.BossTicker; import com.willfp.ecobosses.bosses.tick.BossTicker;
import com.willfp.ecobosses.bosses.tick.tickers.BossBarTicker; import com.willfp.ecobosses.bosses.tick.tickers.BossBarTicker;
import com.willfp.ecobosses.bosses.tick.tickers.HealthPlaceholderTicker; import com.willfp.ecobosses.bosses.tick.tickers.DeathTimeTicker;
import com.willfp.ecobosses.bosses.tick.tickers.NamePlaceholderTicker;
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 lombok.Getter;
@@ -66,7 +67,8 @@ public class LivingEcoBoss extends PluginDependent<EcoPlugin> {
// Tickers // Tickers
this.tickers = new ArrayList<>(); this.tickers = new ArrayList<>();
this.tickers.add(new HealthPlaceholderTicker()); this.tickers.add(new NamePlaceholderTicker());
this.tickers.add(new DeathTimeTicker());
this.tickers.add(new TargetTicker(boss.getTargetMode(), boss.getTargetDistance())); this.tickers.add(new TargetTicker(boss.getTargetMode(), boss.getTargetDistance()));
if (boss.isBossbarEnabled()) { if (boss.isBossbarEnabled()) {
this.tickers.add( this.tickers.add(
@@ -96,6 +98,10 @@ public class LivingEcoBoss extends PluginDependent<EcoPlugin> {
entity.setPersistent(true); entity.setPersistent(true);
entity.setRemoveWhenFarAway(false); entity.setRemoveWhenFarAway(false);
if (boss.getTimeToLive() > 0) {
entity.setMetadata("death-time", this.getPlugin().getMetadataValueFactory().create(System.currentTimeMillis() + (boss.getTimeToLive() * 1000L)));
}
entity.setCustomName(boss.getDisplayName()); entity.setCustomName(boss.getDisplayName());
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);

View File

@@ -0,0 +1,25 @@
package com.willfp.ecobosses.bosses.tick.tickers;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.tick.BossTicker;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;
public class DeathTimeTicker implements BossTicker {
@Override
public void tick(@NotNull final EcoBoss boss,
@NotNull final LivingEntity entity,
final long tick) {
if (boss.getTimeToLive() < 0) {
return;
}
int timeLeft;
timeLeft = (int) (entity.getMetadata("death-time").get(0).asLong() - System.currentTimeMillis());
timeLeft = (int) Math.ceil(timeLeft / 1000D);
if (timeLeft <= 0) {
entity.remove();
boss.removeLivingBoss(entity);
}
}
}

View File

@@ -1,16 +0,0 @@
package com.willfp.ecobosses.bosses.tick.tickers;
import com.willfp.eco.util.StringUtils;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.tick.BossTicker;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;
public class HealthPlaceholderTicker implements BossTicker {
@Override
public void tick(@NotNull final EcoBoss boss,
@NotNull final LivingEntity entity,
final long tick) {
entity.setCustomName(boss.getDisplayName().replace("%health%", StringUtils.internalToString(entity.getHealth())));
}
}

View File

@@ -0,0 +1,30 @@
package com.willfp.ecobosses.bosses.tick.tickers;
import com.willfp.eco.util.StringUtils;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.tick.BossTicker;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;
public class NamePlaceholderTicker implements BossTicker {
@Override
public void tick(@NotNull final EcoBoss boss,
@NotNull final LivingEntity entity,
final long tick) {
int timeLeft = -1;
if (boss.getTimeToLive() > 0) {
timeLeft = (int) (entity.getMetadata("death-time").get(0).asLong() - System.currentTimeMillis());
timeLeft = (int) Math.ceil(timeLeft / 1000D);
}
String time = "";
if (timeLeft > 0) {
time = String.format("%d:%02d", timeLeft/60, timeLeft%60);
}
entity.setCustomName(
boss.getDisplayName()
.replace("%health%", StringUtils.internalToString(entity.getHealth()))
.replace("%time%", time)
);
}
}

View File

@@ -12,6 +12,7 @@ max-health: 300
attack-damage: 30 attack-damage: 30
movement-speed: 1.2 movement-speed: 1.2
follow-range: 20 follow-range: 20
time-to-live: 120 # Time to live before auto despawn, in seconds. Set to -1 to disable.
auto-spawn-interval: -1 # Time between auto spawns in ticks (20 ticks in a second) - Set to -1 to disable. auto-spawn-interval: -1 # Time between auto spawns in ticks (20 ticks in a second) - Set to -1 to disable.
auto-spawn-locations: [ ] # Formatted as world:x:y:z - for example world_nether:100:10:100 auto-spawn-locations: [ ] # Formatted as world:x:y:z - for example world_nether:100:10:100