Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package games.coob.core.block;
- import org.bukkit.Bukkit;
- import org.bukkit.Chunk;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.entity.Arrow;
- import org.bukkit.entity.Player;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- import org.mineacademy.fo.EntityUtil;
- import org.mineacademy.fo.RandomUtil;
- import org.mineacademy.fo.remain.CompMaterial;
- public class BlockTask extends BukkitRunnable {
- // pick a random location
- // call a method for it
- // e.g. > crops grow FASTER than in normal MC
- @Override
- public void run() {
- //System.out.println("Task running");
- // Homework : create a two-phased system
- // Project : shooting blocks
- final BlockRegistry blockRegistry = BlockRegistry.getInstance();
- for (final World world : Bukkit.getWorlds())
- for (final Chunk chunk : world.getLoadedChunks()) {
- final Block randomBlock = chunk.getBlock(
- RandomUtil.nextBetween(0, 15),
- RandomUtil.nextBetween(0, world.getMaxHeight() - 1),
- RandomUtil.nextBetween(0, 15));
- //System.out.println("Ticking " + randomBlock);
- /*if (!BlockVisualizer.isVisualized(randomBlock))
- BlockVisualizer.visualize(randomBlock, CompMaterial.BEACON, "Ticked Right Now");
- Common.runLater(20, () -> {
- if (BlockVisualizer.isVisualized(randomBlock))
- BlockVisualizer.stopVisualizing(randomBlock);
- });*/
- if (blockRegistry.isRegistered(randomBlock)) {
- final Block blockAbove = randomBlock.getRelative(BlockFace.UP);
- if (randomBlock.getType() == CompMaterial.FARMLAND.getMaterial() & blockAbove.getType() == CompMaterial.WHEAT.getMaterial()) {
- if (blockAbove.getBlockData() instanceof final org.bukkit.block.data.Ageable ageable) {
- ageable.setAge(ageable.getMaximumAge());
- blockAbove.setBlockData(ageable);
- }
- }
- }
- }
- // Get the block level
- // If level 1 : shoot an arrow to the nearest player
- // Level 2 : shoot a poisonness arrow to the nearest player
- for (final Location location : blockRegistry.getLocations()) {
- final Block block = location.getBlock();
- if (block.getType() == CompMaterial.DIAMOND_BLOCK.getMaterial()) {
- if (blockRegistry.getLevel(block) == 1) {
- final Player closestPlayer = EntityUtil.findNearestEntity(location, 10, Player.class);
- shootArrow(closestPlayer, block);
- }
- }
- }
- }
- public void shootArrow(final Player target, final Block block) {
- if (target != null) {
- final Location location = block.getLocation();
- location.setY(location.getY() + 1.2);
- location.setX(location.getX() + 0.5);
- location.setZ(location.getZ() + 0.5);
- final Vector vector = target.getLocation().subtract(block.getLocation()).toVector().normalize();
- final Arrow arrow = block.getWorld().spawnArrow(location, vector, 1, 0);
- arrow.setVelocity(vector.multiply(2).add(new Vector(0, 0.1, 0)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement