Search in sources :

Example 56 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Skills by StarTux.

the class BukkitSkillsPlugin method onEnable.

@Override
public void onEnable() {
    // Files
    writeDefaultFiles(false);
    reloadConfig();
    // Economy
    if (!setupEconomy()) {
        getLogger().warning("Economy setup failed. Disabling skills.");
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // Database
    db = new SQLDatabase(this);
    for (Class<?> clazz : SQLDB.getDatabaseClasses()) db.registerTable(clazz);
    if (!db.createAllTables()) {
        getLogger().warning("Database setup failed. Disabling skills.");
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // Skills
    skills.configure();
    for (BukkitSkill skill : skills.getSkills()) {
        if (skill instanceof Listener) {
            getServer().getPluginManager().registerEvents((Listener) skill, this);
        } else {
            getLogger().warning("Not an Event Listener: " + skill.getDisplayName());
        }
    }
    // Double check skills
    for (BukkitSkillType type : BukkitSkillType.values()) {
        BukkitSkill skill = skills.getSkillMap().get(type);
        if (skill == null) {
            getLogger().warning("Missing skill: " + type.name());
        } else {
            skill.configureSkill();
            skill.onEnable();
        }
    }
    // Commands
    getCommand("skillsadmin").setExecutor(adminCommand);
    getCommand("skills").setExecutor(skillsCommand);
    getCommand("highscore").setExecutor(highscoreCommand);
    // Events
    getServer().getPluginManager().registerEvents(this, this);
    // Tasks
    new BukkitRunnable() {

        @Override
        public void run() {
            saveSome();
            updateAllPlayers();
        }
    }.runTaskTimer(this, 20, 20);
    // 
    skills.buildNameMap();
}
Also used : Listener(org.bukkit.event.Listener) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) SQLDatabase(com.winthier.sql.SQLDatabase)

Example 57 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.

the class PlayerDeath method onDeath.

@EventHandler
public void onDeath(PlayerDeathEvent event) {
    final UPlayer player = new UPlayer(event);
    event.setDeathMessage(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + player.getName() + " died near " + player.getLastTown().getName());
    event.setKeepInventory(true);
    if (player.getLifeCrystals() > 0) {
        player.setLifeCrystals(player.getLifeCrystals() - 1);
    } else {
        player.getInventory().dropItems(player.getLocation());
        player.getInventory().clear();
    }
    new BukkitRunnable() {

        public void run() {
            player.spigot().respawn();
        }
    }.runTaskLater(Main.getInstance(), 3L);
    new BukkitRunnable() {

        public void run() {
            player.setMana(20);
            CustomHealth.updateMaxHealth(player);
            player.heal();
            player.teleport(player.getLastTown().getSpawnLocation());
        }
    }.runTaskLater(Main.getInstance(), 25L);
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 58 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.

the class PlayerInteract method onTrample.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onTrample(PlayerInteractEvent event) {
    if (event.getAction() == Action.PHYSICAL) {
        Block block = event.getClickedBlock();
        if (block == null) {
            return;
        }
        Material material = block.getType();
        if (material == Material.SOIL) {
            event.setUseInteractedBlock(PlayerInteractEvent.Result.DENY);
            event.setCancelled(true);
            // Set soil as not hydrated
            block.setType(Material.SOIL);
            block.setData((byte) 0);
            final Block block2 = block;
            new BukkitRunnable() {

                public void run() {
                    // Set soil as hydrated
                    block2.setData((byte) 7);
                }
            }.runTaskLater(Main.getInstance(), 2 * 20);
            // The code below slowly grows the weat plant.
            Location loc = block.getLocation();
            final Block wheat = new Location(Var.WORLD, loc.getX(), loc.getY() + 1, loc.getZ()).getBlock();
            wheat.setType(Material.CROPS);
            new BukkitRunnable() {

                public void run() {
                    byte data = wheat.getData();
                    Logger.log(LogLevel.DEBUG, "Crops", "Someone trampled me! Current current growing state: " + data);
                    // I used >= just for safety, it shouldn't matter.
                    if (data >= 7) {
                        this.cancel();
                        return;
                    }
                    wheat.setData((byte) (data + 1));
                }
            }.runTaskTimer(Main.getInstance(), 0, 20);
        }
    }
}
Also used : Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Material(org.bukkit.Material) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 59 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.

the class PlayerLoginRoom method onMove.

@EventHandler(priority = EventPriority.MONITOR)
public void onMove(PlayerMoveEvent event) {
    final UPlayer player = new UPlayer(event);
    if (TELEPORT_COOLDOWN.contains(player.getName())) {
        return;
    }
    if (!isInRange(player)) {
        return;
    }
    Block blockStandingOn = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
    if (blockStandingOn.getType() == Material.BEDROCK) {
        TELEPORT_COOLDOWN.add(player.getName());
        new BukkitRunnable() {

            public void run() {
                if (TELEPORT_COOLDOWN.contains(player.getName())) {
                    TELEPORT_COOLDOWN.remove(player.getName());
                }
            }
        }.runTaskLater(Main.getInstance(), 10 * 20);
        YamlConfiguration config = DataFile.PLAYER_LOCATION.getConfig();
        String locationString = config.getString(player.getUniqueId().toString());
        Location location;
        if (locationString == null) {
            location = new Location(Var.WORLD, 1, 67, -2, 0, 0);
        } else {
            location = LocationUtils.getLocationFromString(locationString);
        }
        player.teleport(location);
        Ublisk.spawnParticle(Particle.EXPLOSION_NORMAL, location, 20, 0, 0, 0, 0.1);
        player.removePotionEffect(PotionEffectType.INVISIBILITY);
        if (IN_PORTAL_ROOM.contains(player.getName())) {
            IN_PORTAL_ROOM.remove(player.getName());
        }
        player.setAbilitiesEnabled(true);
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Block(org.bukkit.block.Block) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 60 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.

the class MobSpawn method startMobSpawning.

public static void startMobSpawning() {
    if (MOB_SPAWNING_ACTIVE) {
        throw new UnsupportedOperationException("Mob spawning is already active");
    } else {
        MOB_SPAWNING_ACTIVE = true;
    }
    for (final Mob mob : Mobs.MOB_LIST) {
        double rate = mob.getSpawnRate() * 20;
        new BukkitRunnable() {

            public void run() {
                if (Bukkit.getOnlinePlayers().size() == 0 || mob.hasReachedSpawnLimit()) {
                    return;
                }
                Radius area = mob.getArea();
                boolean positiveX = Random.getRandomBoolean();
                boolean positiveZ = Random.getRandomBoolean();
                int radius = area.getRadius();
                int x = area.getX();
                int z = area.getZ();
                int randomX = Random.getRandomInteger(0, radius);
                int randomZ = Random.getRandomInteger(0, radius);
                if (positiveX) {
                    x = x + randomX;
                } else {
                    x = x - randomX;
                }
                if (positiveZ) {
                    z = z + randomZ;
                } else {
                    z = z - randomZ;
                }
                Location loc = new Location(Var.WORLD, x + 0.5, area.getY(), z + 0.5);
                if (!loc.getChunk().isLoaded()) {
                    return;
                }
                boolean noPlayerNearby = true;
                for (Player player : Var.WORLD.getEntitiesByClass(Player.class)) {
                    if (player.getLocation().distanceSquared(loc) < Math.pow(MAXIMUM_DISTANCE + area.getY(), 2)) {
                        noPlayerNearby = false;
                        break;
                    }
                }
                if (noPlayerNearby) {
                    return;
                }
                while (MOB_SPAWNING_AIR_BLOCKS.contains(loc.getBlock().getType())) {
                    loc.setY(loc.getY() - 1);
                }
                // Don't let mobs spawn on top of some blocks
                if (MOB_SPAWNING_CANCEL.contains(loc.getBlock().getType())) {
                    return;
                }
                loc.setY(loc.getY() + 1);
                if (!MOB_SPAWNING_AIR_BLOCKS.contains(loc.getBlock().getType()))
                    return;
                String name = DARK_AQUA + mob.getName() + DARK_GRAY + " [" + DARK_GREEN + mob.getLevel() + DARK_GRAY + "]";
                LivingEntity entity = (LivingEntity) Var.WORLD.spawnEntity(loc, mob.getEntityType());
                // Apply custom data
                entity.setCustomName(name);
                entity.setCustomNameVisible(true);
                double health = mob.getHealth();
                entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(health);
                entity.setHealth(health);
                entity.setRemoveWhenFarAway(true);
                // Look in a random direction
                Location tp = entity.getLocation();
                tp.setYaw(Random.getRandomInteger(0, 360));
                entity.teleport(tp);
                Ublisk.spawnParticle(Particle.EXPLOSION_NORMAL, tp, 20, 0, 0, 0, 0.1);
                // Execute mob code, if any
                MobCode code = mob.getMobCode();
                if (code != null)
                    code.mobCode(entity);
                Mobs.SPAWNED_MOBS.put(entity.getUniqueId(), mob);
            }
        }.runTaskTimer(Main.getInstance(), 2 * 20, (long) rate);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) 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