getCommand(string)返回null值

发布于 2025-01-31 05:42:12 字数 1411 浏览 3 评论 0原文

我是Minecraft插件开发的新手,我有一个问题,而不是无法解决。

当他在聊天中写入 /点时,我会尝试回应发件人。我在第一堂课中有这个:

package fr.azmog25.pointsaver.pointsaver;
import org.bukkit.plugin.java.JavaPlugin;

public final class PointSaver extends JavaPlugin {

    @Override
    public void onEnable() {
        // Plugin startup logic
        System.out.println("Serveur lancé !");
        System.out.println(this.getCommand("point"));
    }

    @Override
    public void onDisable() {
        // Plugin shutdown logic
        System.out.println("Serveur éteint !");
    }
}

我的第二类外观是这样的:

package fr.azmog25.pointsaver.pointsaver;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class PointAdder implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if(!(sender instanceof Player)) {
        System.out.println("Vous devez être un joueur !");
        return false;
    }

    Player player = (Player) sender;
    player.sendMessage("bravo ça marche !");
    return true;
}

and

插件。

name: PointSaver
version: 1.0
main: fr.azmog25.pointsaver.pointsaver.PointSaver
commands:
  point:
    description: Save coordinates
    permission: point.use

}

I'm new in minecraft plugins development and I have a problem than i can't solve.

I try to response to the sender when he write /point in the chat. I have this in my first class:

package fr.azmog25.pointsaver.pointsaver;
import org.bukkit.plugin.java.JavaPlugin;

public final class PointSaver extends JavaPlugin {

    @Override
    public void onEnable() {
        // Plugin startup logic
        System.out.println("Serveur lancé !");
        System.out.println(this.getCommand("point"));
    }

    @Override
    public void onDisable() {
        // Plugin shutdown logic
        System.out.println("Serveur éteint !");
    }
}

My second class look's like this :

package fr.azmog25.pointsaver.pointsaver;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class PointAdder implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if(!(sender instanceof Player)) {
        System.out.println("Vous devez être un joueur !");
        return false;
    }

    Player player = (Player) sender;
    player.sendMessage("bravo ça marche !");
    return true;
}

}

and my plugin.yml have :

name: PointSaver
version: 1.0
main: fr.azmog25.pointsaver.pointsaver.PointSaver
commands:
  point:
    description: Save coordinates
    permission: point.use

But the getCommand() always return null and it's my first time in plugin development...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆头 2025-02-07 05:42:12

您需要在OneNable()方法中注册命令。

删除 system.out.println(this.getCommand(“ point”); ,然后将以下代码添加到您的OneNable()方法中。

this.getCommand("point").setExecutor(new PointAdder());

希望可以解决该问题。我也将采取其他答案'建议并确保您的plugin.yml位于正确的位置。

You need to register the command in your onEnable() method.

Remove System.out.println(this.getCommand("point"); and add the below code into your onEnable() method.

this.getCommand("point").setExecutor(new PointAdder());

That should hopefully fix the issue. I would also take the other answers' advice and make sure your plugin.yml is in the right spot.

谁的新欢旧爱 2025-02-07 05:42:12

您不需要将执行器添加到您的命令中才能返回某些内容吗?
this.getCommand(“ point”)。setExeCutor(new PointAdder());

它可能应该修复您的东西。

(+根据您的最后一条评论,插件.yml文件应位于jar文件的根部。)

Don't you need to add an executor to your command to make it return something ?
this.getCommand("point").setExecutor(new PointAdder());

It should probably fix your stuff.

(+ According to your last comment the plugin.yml file should be at the root of your jar file.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文