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.Effect;
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!");
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
Player player = (Player) sender;
if(commandLabel.equalsIgnoreCase("firehorse") || commandLabel.equalsIgnoreCase("fh")){
Horse horse = (Horse) player.getWorld().spawnEntity(player.getLocation(), EntityType.HORSE);
horse.setBreed(true);
horse.setAdult();
horse.setVariant(Variant.SKELETON_HORSE);
horse.setCustomName(player.getDisplayName() + "'s Fire Horse");
horse.getWorld().playEffect(horse.getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
}
return false;
}
}
答案 0 :(得分:3)
使用Scheduler Programming。您可以创建一个重复任务,每隔几个刻度生成粒子:
getServer().getScheduler().runTaskTimer(this, new Runnable() {
public void run() {
horse.getWorld().playEffect(horse.getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
}
}, 0L, 10L);
只需将当前playEffect
行替换为该行,并使horse
成为最终版。
答案 1 :(得分:1)
如果你想创建一个循环,你应该使用Bukkit的内置SchedulerAPI - explained here。
以下是使用您的代码的示例:
创建一个名为HorseTimer的新类(或任何你想要的)。让它实现Runnable类。
public class HorseTimer implements Runnable {
@Override
public void run() {
}
}
然后添加一个构造函数,以便类知道产生粒子的实体。
public class HorseTimer implements Runnable {
private Horse horse;
public HorseTimer(Horse horse) {
this.horse = horse;
}
@Override
public void run() {
}
}
现在你可以在马周围产生粒子(就像你只做一次一样)。
public class HorseTimer implements Runnable {
private Horse horse;
public HorseTimer(Horse horse) {
this.horse = horse;
}
@Override
public void run() {
// Do stuff with the horse, will be in the loop.
}
}
最后,我们需要在Main类中启动循环。将此代码放在onCommand(...)方法的if语句的末尾。
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new HorseTimer(horse), 0l, <DELAY BETWEEN REPEATS IN TICKS HERE>l);