Search in sources :

Example 6 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class Command_lockup method startLockup.

private void startLockup(final Player player) {
    final FPlayer playerdata = plugin.pl.getPlayer(player);
    cancelLockup(playerdata);
    playerdata.setLockupScheduleId(new BukkitRunnable() {

        @Override
        public void run() {
            if (player.isOnline()) {
                player.openInventory(player.getInventory());
            } else {
                cancelLockup(playerdata);
            }
        }
    }.runTaskTimer(plugin, 0L, 5L));
}
Also used : FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 7 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class FSync method playerMsg.

public static void playerMsg(final Player player, final String message) {
    final TotalFreedomMod plugin = TotalFreedomMod.plugin();
    new BukkitRunnable() {

        @Override
        public void run() {
            FUtil.playerMsg(player, message);
        }
    }.runTask(plugin);
}
Also used : TotalFreedomMod(me.totalfreedom.totalfreedommod.TotalFreedomMod) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 8 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class RollbackManager method rollback.

public int rollback(final String playerName) {
    final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
    if (entries == null) {
        return 0;
    }
    int count = entries.size();
    for (RollbackEntry entry : entries) {
        if (entry != null) {
            entry.restore();
        }
    }
    if (!removeHistory.contains(playerName.toLowerCase())) {
        removeHistory.add(playerName.toLowerCase());
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            if (removeHistory.contains(playerName.toLowerCase())) {
                removeHistory.remove(playerName.toLowerCase());
                purgeEntries(playerName);
            }
        }
    }.runTaskLater(plugin, 40L * 20L);
    return count;
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 9 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project GameCore by Warvale.

the class GlobalEvent method onBlockBreak.

@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    if (event.getBlock().getType().equals(Material.IRON_ORE)) {
        event.getPlayer().giveExp(10);
        for (int i = 0; i < NumberUtils.random(3, 1); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.IRON_INGOT));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.IRON_NUGGET);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.forEach(Entity::remove);
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.IRON_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 5, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.GOLD_ORE)) {
        event.getPlayer().giveExp(30);
        for (int i = 0; i < NumberUtils.random(2, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.GOLD_INGOT));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.GOLD_NUGGET);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.GOLD_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.DIAMOND_ORE)) {
        event.getPlayer().giveExp(50);
        for (int i = 0; i < NumberUtils.random(1, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.DIAMOND));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.PRISMARINE_CRYSTALS);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.DIAMOND_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 25, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.LAPIS_ORE)) {
        event.getPlayer().giveExp(50);
        for (int i = 0; i < NumberUtils.random(1, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.LAPIS_BLOCK));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.EYE_OF_ENDER);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.LAPIS_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 15, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
}
Also used : Arrays(java.util.Arrays) Entity(org.bukkit.entity.Entity) Enchantment(org.bukkit.enchantments.Enchantment) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) NumberUtils(net.warvale.core.utils.NumberUtils) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) PlayerPickupItemEvent(org.bukkit.event.player.PlayerPickupItemEvent) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) TeamManager(net.warvale.core.game.logic.TeamManager) EventHandler(org.bukkit.event.EventHandler) Vector(org.bukkit.util.Vector) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) List(java.util.List) ChatUtils(net.warvale.core.utils.chat.ChatUtils) Location(org.bukkit.Location) ChatColor(org.bukkit.ChatColor) Material(org.bukkit.Material) Listener(org.bukkit.event.Listener) Entity(org.bukkit.entity.Entity) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 10 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.

the class RotateCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    final List<dEntity> entities = new ArrayList<dEntity>((List<dEntity>) scriptEntry.getObject("entities"));
    final Duration duration = (Duration) scriptEntry.getObject("duration");
    final Duration frequency = (Duration) scriptEntry.getObject("frequency");
    final Element yaw = (Element) scriptEntry.getObject("yaw");
    final Element pitch = (Element) scriptEntry.getObject("pitch");
    boolean cancel = scriptEntry.hasObject("cancel");
    final boolean infinite = scriptEntry.hasObject("infinite");
    // Report to dB
    dB.report(scriptEntry, getName(), (cancel ? aH.debugObj("cancel", cancel) : "") + aH.debugObj("entities", entities.toString()) + (infinite ? aH.debugObj("duration", "infinite") : duration.debug()) + frequency.debug() + yaw.debug() + pitch.debug());
    // them from it
    for (dEntity entity : entities) {
        if (cancel) {
            rotatingEntities.remove(entity.getUUID());
        } else {
            rotatingEntities.add(entity.getUUID());
        }
    }
    // Go no further if we are canceling a rotation
    if (cancel) {
        return;
    }
    // Run a task that will keep rotating the entities
    BukkitRunnable task = new BukkitRunnable() {

        int ticks = 0;

        int maxTicks = duration.getTicksAsInt();

        // Track entities that are no longer used, to remove them from
        // the regular list
        Collection<dEntity> unusedEntities = new LinkedList<dEntity>();

        @Override
        public void run() {
            if (entities.isEmpty()) {
                scriptEntry.setFinished(true);
                this.cancel();
            } else if (infinite || ticks < maxTicks) {
                for (dEntity entity : entities) {
                    if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
                        NMSHandler.getInstance().getEntityHelper().rotate(entity.getBukkitEntity(), NMSHandler.getInstance().getEntityHelper().normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()), entity.getLocation().getPitch() + pitch.asFloat());
                    } else {
                        rotatingEntities.remove(entity.getUUID());
                        unusedEntities.add(entity);
                    }
                }
                // Remove any entities that are no longer spawned
                if (!unusedEntities.isEmpty()) {
                    for (dEntity unusedEntity : unusedEntities) {
                        entities.remove(unusedEntity);
                    }
                    unusedEntities.clear();
                }
                ticks = (int) (ticks + frequency.getTicks());
            } else {
                scriptEntry.setFinished(true);
                this.cancel();
            }
        }
    };
    task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, frequency.getTicks());
}
Also used : net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Duration(net.aufdemrand.denizencore.objects.Duration)

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