Search in sources :

Example 81 with BukkitRunnable

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));
}
Also used : BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Test(org.junit.Test)

Example 82 with BukkitRunnable

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);
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) HashSet(java.util.HashSet)

Example 83 with BukkitRunnable

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);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 84 with BukkitRunnable

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);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 85 with BukkitRunnable

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);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Location(org.bukkit.Location)

Aggregations

BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)316 Player (org.bukkit.entity.Player)85 EventHandler (org.bukkit.event.EventHandler)52 Location (org.bukkit.Location)46 Vector (org.bukkit.util.Vector)45 Entity (org.bukkit.entity.Entity)29 ItemStack (org.bukkit.inventory.ItemStack)26 List (java.util.List)25 UUID (java.util.UUID)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)18 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)17 LivingEntity (org.bukkit.entity.LivingEntity)16 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)15 HashMap (java.util.HashMap)12 MyPetFeedEvent (de.Keyle.MyPet.api.event.MyPetFeedEvent)11 Material (org.bukkit.Material)11 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)10 File (java.io.File)10 PotionEffect (org.bukkit.potion.PotionEffect)10