Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
yxc0915 authored Mar 19, 2024
0 parents commit c13be96
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
53 changes: 53 additions & 0 deletions FlyTimePlugin.java
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;
}
}
9 changes: 9 additions & 0 deletions plugin.yml
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: 你没有使用这个命令的权限。

0 comments on commit c13be96

Please sign in to comment.