use of org.bukkit.scheduler.BukkitRunnable in project AuthMeReloaded by AuthMe.
the class BukkitServiceTest method shouldRunTaskTimerAsynchronously.
@Test
public void shouldRunTaskTimerAsynchronously() {
// given
BukkitRunnable task = new BukkitRunnable() {
@Override
public void run() {
}
};
long delay = 20L;
long period = 4000L;
BukkitTask bukkitTask = mock(BukkitTask.class);
given(task.runTaskTimerAsynchronously(authMe, delay, period)).willReturn(bukkitTask);
// when
BukkitTask resultingTask = bukkitService.runTaskTimerAsynchronously(task, delay, period);
// then
assertThat(resultingTask, equalTo(bukkitTask));
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class CustomBossBossBar method start.
public void start() {
bossBarUpdater = new BukkitRunnable() {
@Override
public void run() {
// This can happen on phase changes where boss bars might not be configured on subsequent entities
if (!customBossEntity.exists() || customBossEntity.getCustomBossesConfigFields().getLocationMessage() == null) {
cancel();
return;
}
HashSet<Player> freshIteration = new HashSet<>();
for (Player player : trackingPlayers) {
freshIteration.add(player);
if (!bossBars.containsKey(player))
createBossBar(player);
updateBossBar(player, bossBars.get(player));
}
// Remove players that have stopped
bossBars.entrySet().removeIf(entry -> {
if (!trackingPlayers.contains(entry.getKey())) {
entry.getValue().removeAll();
return true;
}
return false;
});
// nearby player check
if (customBossEntity.isValid())
for (Entity entity : customBossEntity.getLivingEntity().getNearbyEntities(30, 30, 30)) if (entity.getType().equals(EntityType.PLAYER))
if (!freshIteration.contains((Player) entity))
createBossBar((Player) entity);
}
}.runTaskTimer(MetadataHandler.PLUGIN, 0, 5);
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class NPCEntity method startTalkingCooldown.
/**
* Starts a cooldown for the talking state. Useful to avoid overlapping speech.
*/
public void startTalkingCooldown() {
this.isTalking = true;
new BukkitRunnable() {
@Override
public void run() {
isTalking = false;
}
}.runTaskLater(MetadataHandler.PLUGIN, 20 * 3);
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class Flamethrower method doFlamethrowerPhase1.
/**
* Warning phase
*
* @param eliteEntity
*/
private void doFlamethrowerPhase1(EliteEntity eliteEntity, Location fixedPlayerLocation) {
eliteEntity.getLivingEntity().setAI(false);
new BukkitRunnable() {
int counter = 0;
@Override
public void run() {
if (!eliteEntity.isValid()) {
cancel();
return;
}
doParticleEffect(eliteEntity, fixedPlayerLocation, Particle.SMOKE_NORMAL);
counter++;
if (counter < 20 * 2)
return;
doFlamethrowerPhase2(eliteEntity, fixedPlayerLocation);
cancel();
}
}.runTaskTimer(MetadataHandler.PLUGIN, 0, 1);
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class Flamethrower method doFlamethrowerPhase2.
/**
* Damage phase
*
* @param eliteEntity
*/
private void doFlamethrowerPhase2(EliteEntity eliteEntity, Location fixedPlayerLocation) {
List<Location> damagePoints = generateDamagePoints(eliteEntity, fixedPlayerLocation);
new BukkitRunnable() {
int timer = 0;
@Override
public void run() {
if (!eliteEntity.isValid()) {
cancel();
return;
}
doParticleEffect(eliteEntity, fixedPlayerLocation, Particle.FLAME);
doDamage(damagePoints, eliteEntity);
timer++;
if (timer < 20 * 3)
return;
doFlamethrowerPhase3(eliteEntity, fixedPlayerLocation);
cancel();
}
}.runTaskTimer(MetadataHandler.PLUGIN, 0, 1);
}
Aggregations