所以我目前正忙于开发一个插件,当你在《我的世界》中看到它们来自天空时,它会发射雷击,但与你的弓水平,设置半径为 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);”我被卡住了,我需要用一个代码替换它,使闪电在发射时从弓中射出。
这是主
文件
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
}
}
关于java - 能射出雷击的弓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36890429/