Make SheepBouncer logic cancellable.
Following the changes in 96c1f18517
, this commit makes SheepBouncer cancellable for the same reasons as outlined in the MASpawnThread commit.
This commit is contained in:
parent
96c1f18517
commit
754eb156d1
|
@ -586,6 +586,7 @@ public class ArenaImpl implements Arena
|
|||
|
||||
// Stop spawning.
|
||||
stopSpawner();
|
||||
stopBouncingSheep();
|
||||
|
||||
// Announce and clean arena floor, etc.
|
||||
if (settings.getBoolean("global-end-announce", false)) {
|
||||
|
@ -1030,15 +1031,24 @@ public class ArenaImpl implements Arena
|
|||
world.setSpawnFlags(allowMonsters, allowAnimals);
|
||||
}
|
||||
|
||||
private void startBouncingSheep()
|
||||
{
|
||||
// Create a new bouncer if necessary.
|
||||
if (sheepBouncer == null) {
|
||||
sheepBouncer = new SheepBouncer(this);
|
||||
private void startBouncingSheep() {
|
||||
if (sheepBouncer != null) {
|
||||
sheepBouncer.stop();
|
||||
sheepBouncer = null;
|
||||
}
|
||||
|
||||
// Start bouncing!
|
||||
scheduleTask(sheepBouncer, settings.getInt("first-wave-delay", 5) * 20);
|
||||
|
||||
sheepBouncer = new SheepBouncer(this);
|
||||
sheepBouncer.start();
|
||||
}
|
||||
|
||||
private void stopBouncingSheep() {
|
||||
if (sheepBouncer == null) {
|
||||
plugin.getLogger().warning("Can't stop non-existent sheep bouncer in arena " + configName() + ". This should never happen.");
|
||||
return;
|
||||
}
|
||||
|
||||
sheepBouncer.stop();
|
||||
sheepBouncer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.garbagemule.MobArena.waves;
|
||||
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -13,11 +15,34 @@ public class SheepBouncer implements Runnable
|
|||
public static final int BOUNCE_INTERVAL = 20;
|
||||
private Arena arena;
|
||||
private Set<LivingEntity> sheep;
|
||||
|
||||
private BukkitTask task;
|
||||
|
||||
public SheepBouncer(Arena arena) {
|
||||
this.arena = arena;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (task != null) {
|
||||
arena.getPlugin().getLogger().warning("Starting sheep bouncer in arena " + arena.configName() + " with existing bouncer still running. This should never happen.");
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
|
||||
int delay = arena.getSettings().getInt("first-wave-delay", 5) * 20;
|
||||
task = Bukkit.getScheduler().runTaskLater(arena.getPlugin(), this, delay);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (task == null) {
|
||||
arena.getPlugin().getLogger().warning("Can't stop non-existent sheep bouncer in arena " + arena.configName() + ". This should never happen.");
|
||||
return;
|
||||
}
|
||||
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// If the arena isn't running or has no players, bail out
|
||||
|
@ -63,7 +88,7 @@ public class SheepBouncer implements Runnable
|
|||
}
|
||||
|
||||
// Reschedule for more bouncy madness!
|
||||
arena.scheduleTask(this, BOUNCE_INTERVAL);
|
||||
task = Bukkit.getScheduler().runTaskLater(arena.getPlugin(), this, BOUNCE_INTERVAL);
|
||||
}
|
||||
|
||||
/*private boolean isTargetNearby(Creature c, LivingEntity t) {
|
||||
|
|
Loading…
Reference in New Issue