ElaBosak233 / Valkyrie

一个面向中文社区的 Bukkit / Spigot 插件开发教程
https://valkyrie.ela.ac.cn
MIT License
27 stars 3 forks source link

关于TabExecutor的问题 #13

Closed L1-An closed 4 years ago

L1-An commented 4 years ago

我已经按照valkyrie上的教程写下了tabexecutor的类,并且放在Command.java类中,`public class Command implements TabExecutor { @Override public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { if (sender instanceof Player) { Player p = (Player) sender; if (p.hasPermission("val.op")) { if (args.length == 0) { p.sendMessage("缺少子命令"); return true; } else if (args[0].equalsIgnoreCase("name")) { p.sendMessage("Hello, " + p.getName()); return true; } else if (args[0].equalsIgnoreCase("uuid")) { p.sendMessage("Hello, your UUID is " + p.getUniqueId()); return true; } else { p.sendMessage("子命令无效"); return true; } } else { p.sendMessage("你没有权限执行该指令"); return true; } } else { sender.sendMessage("你不是玩家无法执行该命令"); return true; } }

@Override
public List<String> onTabComplete(CommandSender sender, org.bukkit.command.Command command, String alias, String[] args) {
    if (args.length == 1) {
        List<String> subCommands = new ArrayList<>();
        subCommands.add("name");
        subCommands.add("uuid");
        return subCommands;
    }
    return null;
}

} 具体是这么写的,但是当我放入服务器后却显示报错信息如下 [23:25:14 ERROR]: Error occurred while enabling Valkyrie v1.0-SNAPSHOT (Is it up to date?) java.lang.NullPointerException: null at com.shiyu.valkyrie.Valkyrie.onEnable(Valkyrie.java:14) ~[?:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:265) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:347) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:410) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugin(CraftServer.java:436) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugins(CraftServer.java:350) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at net.minecraft.server.v1_13_R2.MinecraftServer.l(MinecraftServer.java:580) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:542) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:420) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at net.minecraft.server.v1_13_R2.DedicatedServer.init(DedicatedServer.java:294) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:698) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3] at java.lang.Thread.run(Unknown Source) [?:1.8.0_211] 在主类中是这样写的 @Override public void onEnable() { // Plugin startup logic Bukkit.getPluginCommand("val").setExecutor(new Command()); }`

ElaBosak233 commented 4 years ago

因为控制台报错的是 java.lang.NullPointerException: null(空指针错误),但还要确认的是 at com.shiyu.valkyrie.Valkyrie.onEnable(Valkyrie.java:14) ~[?:?],也就是 Valkyrie.java 的第 14 行,就要确认一下,有没有在 plugin.yml 注册 val.op 这个权限,因为如果没有注册这个权限,报的就是空指针错误

L1-An commented 4 years ago

感谢指导! 发自我的iPhone

在 2020年8月10日,上午9:13,Ela notifications@github.com 写道:



因为控制台报错的是 java.lang.NullPointerException: null(空指针错误),但还要确认的是 at com.shiyu.valkyrie.Valkyrie.onEnable(Valkyrie.java:14) ~[?:?],也就是 Valkyrie.java 的第 14 行,就要确认一下,有没有在 plugin.yml 注册 val.op 这个权限,因为如果没有注册这个权限,报的就是空指针错误

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ElaBosak233/Valkyrie/issues/13#issuecomment-671127280, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APAJTX443NSKMDUY3IBO4ELR75CR5ANCNFSM4PZHTL4A.

ElaBosak233 commented 4 years ago

感谢指导! 发自我的iPhone 在 2020年8月10日,上午9:13,Ela notifications@github.com 写道:  因为控制台报错的是 java.lang.NullPointerException: null(空指针错误),但还要确认的是 at com.shiyu.valkyrie.Valkyrie.onEnable(Valkyrie.java:14) ~[?:?],也就是 Valkyrie.java 的第 14 行,就要确认一下,有没有在 plugin.yml 注册 val.op 这个权限,因为如果没有注册这个权限,报的就是空指针错误 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#13 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APAJTX443NSKMDUY3IBO4ELR75CR5ANCNFSM4PZHTL4A.

请问事情解决了吗?如果解决了请上 Github 关闭 issue

loinko commented 4 years ago

貌似权限没注册是不会报空指针的,要是能报我就不会那么多次拼错权限找半天找不到哪错了 :joy: onEnable() 那里出错的话,感觉是没有正确在 plugin.yml 里面注册指令,Bukkit.getPluginCommand("val") 返回 null 了

public static PluginCommand getPluginCommand(java.lang.String name) 返回: 找不到则返回null

L1-An commented 4 years ago

感谢指导! 发自我的iPhone 在 2020年8月10日,上午9:13,Ela notifications@github.com 写道:  因为控制台报错的是 java.lang.NullPointerException: null(空指针错误),但还要确认的是 at com.shiyu.valkyrie.Valkyrie.onEnable(Valkyrie.java:14) ~[?:?],也就是 Valkyrie.java 的第 14 行,就要确认一下,有没有在 plugin.yml 注册 val.op 这个权限,因为如果没有注册这个权限,报的就是空指针错误 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#13 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APAJTX443NSKMDUY3IBO4ELR75CR5ANCNFSM4PZHTL4A.

请问事情解决了吗?如果解决了请上 Github 关闭 issue

我已经在plugin.yml里面注册了commands以及permissions,具体内容如下: commands: /val: usage: /val description: the main command of the plugin permission: val.op permissions: val.op: description: The main permission of the plugin default: op

loinko commented 4 years ago

我已经在plugin.yml里面注册了commands以及permissions,具体内容如下: commands: /val: usage: /val description: the main command of the plugin permission: val.op permissions: val.op: description: The main permission of the plugin default: op

commands 后面不要加 /

commands:
    foo:
        description: Foo command
L1-An commented 4 years ago

我已经在plugin.yml里面注册了commands以及permissions,具体内容如下: commands: /val: usage: /val description: the main command of the plugin permission: val.op permissions: val.op: description: The main permission of the plugin default: op

commands 后面不要加 /

commands:
    foo:
        description: Foo command

原来是犯了这样的低级错误,感谢指正!