在我的插件中,我有一个/duel
命令。除了一件事,我已经做了我需要的一切。当一名玩家死亡时,我需要将杀手传送到2秒后产生。这是我onPlayerDeath()
的样子。
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
Player p = e.getEntity().getPlayer();
Player k = e.getEntity().getKiller();
p.sendMessage(ChatColor.DARK_RED +"[" + ChatColor.DARK_GREEN + "HuntsCraft" + ChatColor.DARK_RED + "]" + ChatColor.RED + " Killed by " + ChatColor.BLUE + k.getName());
k.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.DARK_GREEN + "HuntsCraft" + ChatColor.DARK_RED + "]" + ChatColor.GREEN + " You killed " + ChatColor.BLUE + p.getName());
p.getInventory().clear();
k.getInventory().clear();
p.getEquipment().clear();
k.getEquipment().clear();
k.setFlying(true);
Bukkit.broadcastMessage(ChatColor.DARK_RED + "["+ ChatColor.DARK_GREEN + "HuntsCraft" + ChatColor.DARK_RED + "] " + ChatColor.DARK_AQUA + k.getName() + ChatColor.AQUA + " just beat " + ChatColor.DARK_AQUA + p.getName() + ChatColor.AQUA + " in a duel!");
// Teleport the killer to spawn after 2 seconds
}
我以前做过这个,但我忘记了如何使用它。
答案 0 :(得分:1)
您应该使用Scheduler provided by Bukkit。
另请参阅World.getSpawnLocation()
。
Winner winner = new Winner(k);
/*
* The first argument is the unique instance of the main class
* The second argument is the delay in ticks (1 second = 20 ticks)
*/
winner.runTaskLater(Plugin, 40L);
public class Winner extends BukkitRunnable {
private Player player;
public Winner(Player player) {
this.player = player;
}
@Override
public void run() {
Location spawn = player.getWorld().getSpawnLocation();
player.teleport(spawn);
}
}