为什么我不能从command类和主插件类之外的方法发送命令

cyej8jka  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(301)

我正在使用1.16.2 spigot library/bukkit api我的简单代码:

if (event.getSlot() == 11 && event.getCurrentItem().getType() == Material.STICK) {
        punish.time = " 12 h";
        punish.reason = " Autocane (First Offense)";
        reason = " Autocane (First Offense)";
        punishban();

以及惩罚方法:

public void punishban() {
    reason = " Autocane (First Offense)";

    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tempban " + maincommand.target2 + " 12 h" + reason);

}

错误消息:

[20:11:48] [Server thread/ERROR]: Could not pass event InventoryClickEvent to punishcommand v1.0.0
org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:319) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.PlayerConnection.a(PlayerConnection.java:2186) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.PacketPlayInWindowClick.a(SourceFile:32) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.PacketPlayInWindowClick.a(SourceFile:10) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.TickTask.run(SourceFile:18) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.MinecraftServer.ba(MinecraftServer.java:941) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.MinecraftServer.executeNext(MinecraftServer.java:934) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.MinecraftServer.sleepForTick(MinecraftServer.java:918) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:850) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: org.bukkit.command.CommandException: Unhandled exception executing command 'tempban' in plugin punishcommand v1.0.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.craftbukkit.v1_16_R2.CraftServer.dispatchCommand(CraftServer.java:756) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.Bukkit.dispatchCommand(Bukkit.java:693) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at hh_captain.me.guis.banguis.autocanegui.punishban(autocanegui.java:113) ~[?:?]
        at hh_captain.me.guis.banguis.autocanegui.onClick(autocanegui.java:47) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        ... 18 more
Caused by: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_16_R2.command.ColouredConsoleSender cannot be cast to class org.bukkit.entity.Player (org.bukkit.craftbukkit.v1_16_R2.command.ColouredConsoleSender and org.bukkit.entity.Player are in unnamed module of loader 'app')
        at hh_captain.me.bancommand.captain.tempban.tempban.onCommand(tempban.java:29) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.craftbukkit.v1_16_R2.CraftServer.dispatchCommand(CraftServer.java:756) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at org.bukkit.Bukkit.dispatchCommand(Bukkit.java:693) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        at hh_captain.me.guis.banguis.autocanegui.punishban(autocanegui.java:113) ~[?:?]
        at hh_captain.me.guis.banguis.autocanegui.onClick(autocanegui.java:47) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315) ~[spigot-1.16.2.jar:git-Spigot-b5a13e6-0d8350a]
        ... 18 more

我真的很难找出为什么它不起作用?它可以在其他情况下工作,比如在commandexecutor方法中,但是我已经检查了它所说的错误,但是它实际上只是dispatchcommand部分,所以我很困惑。

gkl3eglg

gkl3eglg1#

nvm我修正了它,我只需要删除tempban命令中的施法,因为它是通过控制台运行的,但通过一个玩家施法

相关问题