Fix possible memory leak; resolves #746

This commit is contained in:
Daniel Saukel 2020-04-03 20:46:25 +02:00
parent cc2004b30b
commit 38700a3c62
5 changed files with 14 additions and 8 deletions

View File

@ -49,7 +49,7 @@ public class CommandTask extends BukkitRunnable {
@Override
public void run() {
if (isWorldFinished()) {
if (sign.isWorldFinished()) {
sign.deactivate();
return;
}

View File

@ -16,6 +16,7 @@
*/
package de.erethon.dungeonsxl.sign.windup;
import de.erethon.dungeonsxl.api.DungeonsAPI;
import org.bukkit.scheduler.BukkitRunnable;
/**
@ -23,17 +24,19 @@ import org.bukkit.scheduler.BukkitRunnable;
*/
public class DelayedPowerTask extends BukkitRunnable {
private DungeonsAPI api;
private RedstoneSign sign;
private boolean enable;
public DelayedPowerTask(RedstoneSign sign, boolean enable) {
public DelayedPowerTask(DungeonsAPI api, RedstoneSign sign, boolean enable) {
this.sign = sign;
this.enable = enable;
}
@Override
public void run() {
if (isWorldFinished()) {
if (api.getGameWorld(sign.getSign().getWorld()) != null) {
sign.getEnableTask().cancel();
sign.getDisableTask().cancel();
return;

View File

@ -93,10 +93,14 @@ public class DropSign extends Windup {
setRunnable(new BukkitRunnable() {
@Override
public void run() {
if (isWorldFinished()) {
deactivate();
return;
}
try {
spawnLocation.getWorld().dropItem(spawnLocation, getItem());
} catch (NullPointerException exception) {
cancel();
deactivate();
}
}
});

View File

@ -35,7 +35,7 @@ public class MobSpawnTask extends BukkitRunnable {
@Override
public void run() {
if (isWorldFinished()) {
if (sign.isWorldFinished()) {
sign.deactivate();
return;
}

View File

@ -22,7 +22,6 @@ import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.sign.Rocker;
import de.erethon.dungeonsxl.api.world.InstanceWorld;
import de.erethon.dungeonsxl.player.DPermission;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.scheduler.BukkitTask;
@ -157,11 +156,11 @@ public class RedstoneSign extends Rocker {
}
if (delay > 0) {
enableTask = new DelayedPowerTask(this, true).runTaskTimer(api, delay, delay + offDelay);
enableTask = new DelayedPowerTask(api, this, true).runTaskTimer(api, delay, delay + offDelay);
if (repeat != 1) {
repeatsToDo = repeat;
disableTask = new DelayedPowerTask(this, false).runTaskTimer(api, delay + offDelay, delay + offDelay);
disableTask = new DelayedPowerTask(api, this, false).runTaskTimer(api, delay + offDelay, delay + offDelay);
}
} else {