gpt4 book ai didi

java - 当 Bukkit 中一匹马死亡时停止 Bukkit 循环并记录

转载 作者:行者123 更新时间:2023-12-01 18:28:37 26 4
gpt4 key购买 nike

今天我正在尝试制作一个插件,它可以生成一匹骷髅马,并且马周围有火焰粒子。我把那部分拿下来了,但是每当有人杀死骨马时,火粒子就会留在那里。有人请帮忙吗?

还有我的代码(2类):

package survivalcraft.FireHorse;
import java.util.logging.Logger;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.command.CommandSender;
import org.bukkit.command.Command;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.entity.Player;
import org.bukkit.entity.Horse;
import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Material;

public class Main extends JavaPlugin{
public static Main plugin;
public final Logger logger = Logger.getLogger("Minecraft");

@Override
public void onDisable(){
PluginDescriptionFile pdf = this.getDescription();
this.logger.info(pdf.getName() + " version " + pdf.getVersion() + " has been disabled! Neigh! ;D");
}

@Override
public void onEnable(){
PluginDescriptionFile pdf = this.getDescription();
this.logger.info(pdf.getName() + " version " + pdf.getVersion() + " has been enabled! Neigh! ;D");
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
Player player = (Player) sender;
if(sender instanceof Player){
if(player.hasPermission("firehorse.spawn")){
if(commandLabel.equalsIgnoreCase("firehorse") || commandLabel.equalsIgnoreCase("fh")){
if(args.length == 0){
Horse horse = (Horse) player.getWorld().spawnEntity(player.getLocation(), EntityType.HORSE);
HorseInventory horseinv = null;
ItemStack saddle = new ItemStack(Material.SADDLE);
horse.setVariant(Variant.SKELETON_HORSE);
horse.setCustomName(player.getDisplayName() + "'s Fire Horse");
horse.setTamed(true);
horseinv.setSaddle(saddle);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new HorseTimer(horse), 0l, 5l);
}else{
player.sendMessage(ChatColor.RED + "Usage: /firehorse");
}
}
}else{
player.sendMessage(ChatColor.RED + "You can't spawn a fire horse!");
}
}else{
player.sendMessage(ChatColor.RED + "You must be a player in order to spawn a fire horse!");
}
return false;
}
}

二等:

package survivalcraft.FireHorse;

import org.bukkit.Effect;
import org.bukkit.entity.Horse;

public class HorseTimer implements Runnable{
private Horse horse;

public HorseTimer(Horse horse){
this.horse = horse;
}

@Override
public void run(){
horse.getWorld().playEffect(horse.getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
}
}

最佳答案

第一:检查一匹马是否还活着,就像 @Momo 发布的那样,并由 @CrypticStorm 进行了小修正

第二:HorseTimer 类应该扩展 BukkitRunnable 而不是实现 Rumnable,这样它就可以自行取消请参阅http://wiki.bukkit.org/Scheduler_Programming#Self-Canceling_Example_2

关于java - 当 Bukkit 中一匹马死亡时停止 Bukkit 循环并记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25119125/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com