因此,我目前正忙于使用一个插件,该插件会发出雷击,因为您看到它们来自《我的世界》中的天空,但是从您的弓到水平方向的半径设置为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
方法中,您可以像下面这样使用此类:@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
}
}