-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c13be96
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
public class FlyTimePlugin extends JavaPlugin implements CommandExecutor { | ||
|
||
@Override | ||
public void onEnable() { | ||
this.getCommand("flytime").setExecutor(this); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
if (cmd.getName().equalsIgnoreCase("flytime")) { | ||
if (args.length < 2) { | ||
sender.sendMessage("用法:/flytime <分钟数> <玩家名>"); | ||
return true; | ||
} | ||
|
||
int minutes; | ||
try { | ||
minutes = Integer.parseInt(args[0]); | ||
} catch (NumberFormatException e) { | ||
sender.sendMessage("错误:时间必须是数字。"); | ||
return true; | ||
} | ||
|
||
Player target = Bukkit.getPlayer(args[1]); | ||
if (target == null) { | ||
sender.sendMessage("玩家未找到!"); | ||
return true; | ||
} | ||
|
||
target.setAllowFlight(true); | ||
sender.sendMessage("玩家 " + target.getName() + " 现在可以飞行 " + minutes + " 分钟。"); | ||
|
||
new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
target.setAllowFlight(false); | ||
target.sendMessage("你的飞行权限已关闭。"); | ||
} | ||
}.runTaskLater(this, minutes * 60 * 20); // 20 ticks = 1 second | ||
|
||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: FlyTime | ||
version: 1.0 | ||
main: FlyTimePlugin | ||
commands: | ||
flytime: | ||
description: 给予玩家临时飞行权限。 | ||
usage: /<command> <玩家名> <分钟数> | ||
permission: flytime.use | ||
permission-message: 你没有使用这个命令的权限。 |