diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Windup.java b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Windup.java index ef91ed79..4edc581a 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/sign/Windup.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/sign/Windup.java @@ -184,4 +184,13 @@ public abstract class Windup extends Deactivatable { } } + /** + * Use this method to ensure that its world still exists. + * + * @return if the world is already finished + */ + public boolean isWorldFinished() { + return api.getGameWorld(getSign().getWorld()) != null; + } + } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandTask.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandTask.java index e28d48ae..703d1145 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandTask.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/CommandTask.java @@ -18,7 +18,6 @@ package de.erethon.dungeonsxl.sign.windup; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -50,6 +49,11 @@ public class CommandTask extends BukkitRunnable { @Override public void run() { + if (isWorldFinished()) { + sign.deactivate(); + return; + } + String command = script.getCommands().get(k++).replace("%player%", sender.getName()).replace("%player_name%", sender.getName()); if (papi) { Bukkit.getServer().dispatchCommand(sender, PlaceholderAPI.setPlaceholders(player, command)); diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/DelayedPowerTask.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/DelayedPowerTask.java index e8704d96..eaa5b6d2 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/DelayedPowerTask.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/DelayedPowerTask.java @@ -33,7 +33,7 @@ public class DelayedPowerTask extends BukkitRunnable { @Override public void run() { - if (sign.getGameWorld() == null) { + if (isWorldFinished()) { sign.getEnableTask().cancel(); sign.getDisableTask().cancel(); return; diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java index 25aa9689..d8e1744c 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSign.java @@ -120,7 +120,7 @@ public class MobSign extends Windup { initialAmount = n; provider = attributes.length == 3 ? providers.get(attributes[2]) : null; - setRunnable(new MobSpawnTask(api, this, n)); + setRunnable(new MobSpawnTask(this, n)); } /** diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java index 68542a7d..3239eebb 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/windup/MobSpawnTask.java @@ -16,8 +16,6 @@ */ package de.erethon.dungeonsxl.sign.windup; -import de.erethon.dungeonsxl.api.DungeonsAPI; -import de.erethon.dungeonsxl.api.world.GameWorld; import de.erethon.dungeonsxl.mob.DMob; import org.bukkit.entity.LivingEntity; import org.bukkit.scheduler.BukkitRunnable; @@ -29,17 +27,15 @@ public class MobSpawnTask extends BukkitRunnable { private MobSign sign; private int k, n; - private GameWorld gameWorld; - public MobSpawnTask(DungeonsAPI api, MobSign sign, int n) { + public MobSpawnTask(MobSign sign, int n) { this.sign = sign; - gameWorld = sign.getGameWorld(); this.n = n; } @Override public void run() { - if (gameWorld == null) { + if (isWorldFinished()) { sign.deactivate(); return; }