发射雷击的弓

Bow that shoots lightning strike

所以我目前正忙于开发一个插件,它可以发射雷击,就像你在 minecraft 中看到它们来自天空一样,但是从你的弓是水平的,半径设置为 100 左右

package me.Pixel;

import org.bukkit.FireworkEffect;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.util.BlockIterator;

public class LightningShot implements Listener {

    public Main plugin;

    public LightningShot(Main instance) {
        this.plugin = instance;
    }

    public void onCast(Player p) {
        final BlockIterator blockNext = new BlockIterator(p);
        new Runnable() {
            public int timer = 0;

            public void run() {
                if(this.timer++ > 50) {
                    cancel();
                   }
                if(blockNext.hasNext()) {
                    cancel();
                }
                Block next = blockNext.next();
                try{
                    for(Entity e : LightningShot.this.plugin.getTargets.getTargetList(p, next.getLocation(), 3)) {
                        if(e instanceof LivingEntity) {
                    }
                    FireworkEffectPlayer.playToLocation(next.getLocation(), null);
                }
            }
        }
    }
}

这就是我现在拥有的,但是上面写着 'FireworkEffectPlayer.playToLocation(next.getLocation(), null);' 我卡住了,我需要用一个代码替换它,使闪电在弓发射时从弓中出来。

这是 Main 文件

package me.Pixel;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener {

    public Main plugin;
    public List<String> spells = new ArrayList<String>();
    public getTargets getTargets = new getTargets();

    @Override
    public void onEnable() {
        plugin = this;
        getCommand("bow").setExecutor(new BowCommand());
    }

    @EventHandler
    public void onClick(PlayerInteractEvent e) {
        if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
            Player p = e.getPlayer();
            ItemStack stack = p.getItemInHand();
            if(stack != null &&stack.getType() == Material.BOW && stack.hasItemMeta() && stack.getItemMeta().getDisplayName().equals(ChatColor.RED + "Bow")) {

            }
        }
    }
}

类似这样的事情:http://youtu.be/riPIzITVp0c 但不是雪球而是从 . 希望大家帮帮我!

要让箭在每个刻度(或更少频率)在其位置产生闪电,您可以创建自己的 BukkitRunnable 来跟踪 Arrow 实体,如果箭头着陆、消失或任务耗时过长、自行取消。

这是一个这样的例子 BukkitRunnable:

public class LightningArrowTask extends BukkitRunnable {

    private Arrow arrow; // The arrow to spawn lightning at
    private int tick = 0; // The number of times the run() method has been invoked

    // The constructor that asks for an arrow entity
    public LightningArrowTask(Arrow arrow) {
        this.arrow = arrow;
    }

    @Override
    public void run() {
        // If the arrow no longer exists, has landed, or this task has been running for more than ~10 seconds (200 ticks)
        if (arrow == null || arrow.isOnGround() || tick++ > 20 * 10) {
            this.cancel(); // Cancel the task
        } else {
            arrow.getWorld().strikeLightning(arrow.getLocation()); // Otherwise, make lightning strike at the arrow's location
        }
    }
}

在您的 EntityShootBowEvent 方法中,您可以像这样使用此 class:

@EventHandler
public void onEntityShootBow(EntityShootBowEvent event) {
    if (event.getProjectile() instanceof Arrow) { // If the projectile shot is actually an arrow
        // Add your own conditions here ... such as the name of the bow etc.
        Arrow arrow = (Arrow) event.getProjectile(); // Cast
        // Create the LightningArrowTask BukkitRunnable with the arrow object, run it repeatedly every tick (with a 0 tick delay)
        new LightningArrowTask(arrow).runTaskTimer(this, 0, 1);
        // If you'd like the lightning to only be spawned every 2, 3, 5 etc. ticks, just change that last argument of the runTaskTimer method
    }
}