mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-02 17:00:19 +01:00
Fix possible memory leak
This commit is contained in:
parent
ff1e615d6d
commit
cc2004b30b
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user