getCommand(string)返回null值
我是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在OneNable()方法中注册命令。
删除 system.out.println(this.getCommand(“ point”); ,然后将以下代码添加到您的OneNable()方法中。
希望可以解决该问题。我也将采取其他答案'建议并确保您的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.
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.
您不需要将执行器添加到您的命令中才能返回某些内容吗?
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.)