You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Minecraft插件被/pl识别但/daytime命令无法执行

解决Minecraft插件/daytime命令无效果的问题

以下是针对你遇到的问题的排查和修复步骤:

1. 关键:检查plugin.yml的命令注册

插件能被/pl识别说明主类路径配置正确,但命令必须在plugin.yml中注册,否则Bukkit不会将/daytime路由到你的插件逻辑。

正确的plugin.yml示例:

name: Domenicopluginbello
main: domenicoplugin.domenicopluginbello.Domenicopluginbello
version: 1.0
commands:
  daytime:
    description: 将时间设置为清晨
    usage: /<command>
    permission: domenicoplugin.daytime
    permission-message: 你没有使用该命令的权限!
  • 必须在commands节点下定义daytime命令,否则你的onCommand方法永远不会被触发
  • 确认main字段的路径和代码中的包名+类名完全一致:domenicoplugin.domenicopluginbello.Domenicopluginbello

2. 修复代码中的语法错误

你的代码存在两处明显问题:

  • 重复导入JavaPlugin类
  • 末尾多了一个多余的闭合括号}

修复后的完整代码:

package domenicoplugin.domenicopluginbello;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

public final class Domenicopluginbello extends JavaPlugin {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("daytime")) {
            // 先校验权限,避免无权限用户执行后无反馈
            if (!sender.hasPermission("domenicoplugin.daytime")) {
                sender.sendMessage("你没有使用该命令的权限!");
                return true;
            }
            getServer().getWorlds().get(0).setTime(1000); // 设置为清晨(1000游戏刻)
            sender.sendMessage("时间已设置为清晨。");
            return true;
        }
        return false;
    }
}

3. 权限配置优化

默认情况下,只有服务器OP才能修改游戏时间,普通玩家执行命令会无响应。你可以:

  • 如果要允许所有玩家使用,删除plugin.yml中的permission和permission-message字段
  • 规范做法是给需要的玩家/组分配domenicoplugin.daytime权限,可通过LuckPerms等权限插件配置

4. 可选:优化世界获取逻辑

getServer().getWorlds().get(0)会获取服务器加载的第一个世界,若服务器有多个世界,可能不是你想修改的目标世界。可以指定世界名称并增加空判断:

// 替换原时间设置代码
if (getServer().getWorld("world") != null) {
    getServer().getWorld("world").setTime(1000);
} else {
    sender.sendMessage("目标世界不存在!");
}

内容的提问来源于stack exchange,提问作者Domenico Pezzullo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 22:16:39