9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-24 01:19:22 +00:00

Chunks with bosses in them should not unload

This commit is contained in:
Auxilor
2021-06-30 19:42:31 +01:00
parent 1a364615a3
commit 4ac870f5c3
4 changed files with 50 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import com.willfp.eco.util.StringUtils;
import com.willfp.ecobosses.bosses.effects.Effect;
import com.willfp.ecobosses.bosses.tick.BossTicker;
import com.willfp.ecobosses.bosses.tick.tickers.BossBarTicker;
import com.willfp.ecobosses.bosses.tick.tickers.ChunkLoadTicker;
import com.willfp.ecobosses.bosses.tick.tickers.HealthPlaceholderTicker;
import com.willfp.ecobosses.bosses.tick.tickers.TargetTicker;
import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
@@ -23,9 +24,7 @@ import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
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;
@@ -77,6 +76,7 @@ public class LivingEcoBoss extends PluginDependent {
this.tickers = new ArrayList<>();
this.tickers.add(new HealthPlaceholderTicker());
this.tickers.add(new TargetTicker(boss.getTargetMode(), boss.getTargetDistance()));
this.tickers.add(new ChunkLoadTicker());
if (boss.isBossbarEnabled()) {
this.tickers.add(
new BossBarTicker(

View File

@@ -3,6 +3,7 @@ package com.willfp.ecobosses.bosses.listeners;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.EcoBosses;
import com.willfp.ecobosses.bosses.util.BossUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@@ -35,9 +36,10 @@ public class AutoSpawnTimer implements Runnable {
for (UUID uuid : boss.getLivingBosses().keySet()) {
Entity entity = Bukkit.getEntity(uuid);
if (entity != null) {
worlds.add(entity.getWorld());
}
BossUtils.warnIfNull(entity);
assert entity != null;
worlds.add(entity.getWorld());
}
List<Location> locations = new ArrayList<>(boss.getAutoSpawnLocations());

View File

@@ -0,0 +1,27 @@
package com.willfp.ecobosses.bosses.tick.tickers;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.tick.BossTicker;
import org.bukkit.Chunk;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;
public class ChunkLoadTicker implements BossTicker {
/**
* Create new chunk load ticker.
*/
public ChunkLoadTicker() {
}
@Override
public void tick(@NotNull final EcoBoss boss,
@NotNull final LivingEntity entity,
final long tick) {
if (tick % 10 == 0) {
Chunk chunk = entity.getLocation().getChunk();
if (!chunk.isLoaded()) {
chunk.load();
}
}
}
}

View File

@@ -166,7 +166,21 @@ public class BossUtils {
return;
}
PLUGIN.getLogger().severe("Not-Null boss is null! Generating stacktrace.");
throw new NullPointerException("Not-Null boss is null!");
PLUGIN.getLogger().severe("Boss is null! Report this to Auxilor (https://discord.gg/ZcwpSsE)");
PLUGIN.getLogger().severe("Send this stack-trace in the relevant channel.");
throw new NullPointerException("Boss is null!");
}
/**
* Warn if an entity is null.
*/
public void warnIfNull(@Nullable final Entity entity) {
if (entity != null) {
return;
}
PLUGIN.getLogger().severe("Entity is null! Report this to Auxilor (https://discord.gg/ZcwpSsE)");
PLUGIN.getLogger().severe("Send this stack-trace in the relevant channel.");
throw new NullPointerException("Entity is null!");
}
}