命令运行时的java.lang.ClassCastException。一切正常,内部错误发生消息

时间:2017-02-11 03:30:02

标签: java bukkit

错误:INFO引起:java.lang.ClassCastException:com.ShlobdonG.gMarry.Commands无法强制转换为org.bukkit.plugin.Plugin

代码:

if (cmd.getName().equalsIgnoreCase("vmarry")) {
    if (!(player == null)) {
        if (!player.hasPermission("gmarry.marry")) {
            sender.sendMessage("You can't marry a player because of permission!");
            return true;
        } else {

            int cooldown = this.plugin.getConfig().getInt(
                    "request-cooldown");
            if (this.plugin.vmarry.containsKey(player.getName())) {
                long diff = (System.currentTimeMillis() - this.plugin.vmarry
                        .get(sender.getName())) / 1000;
                if (diff < cooldown) {
                    player.sendMessage("You must wait "
                            + cooldown
                            + " seconds before marrying another player.");
                    return false;
                }
            }
        }
        if (args.length > 0) {
            final Player target = Bukkit.getServer().getPlayer(
                    args[0]);
            long keepAlive = this.plugin.getConfig().getLong(
                    "keep-alive") * 20;

            if (target == null) {
                sender.sendMessage("You can only marry players that are online!");
                return false;
            }
            if (target == player) {
                sender.sendMessage("You can't bite yourself!");
                return false;
            }

            sendRequest(player, target);

            Bukkit.getServer()
                    .getScheduler()
                    .scheduleSyncDelayedTask((Plugin) this,
                            new Runnable() {
                                public void run() {
                                    killRequest(target.getName());
                                }
                            }, keepAlive);

            this.plugin.vmarry.put(player.getName(),
                    System.currentTimeMillis());
        } else {
            player.sendMessage("Attempt to marry player..");
            player.sendMessage("/vmarry <player>");
        }
    }
}

我意识到代码很乱,但导致ClassCatException的问题在哪里?我迷路了...

10.02 22:41:50 [Server] INFO ... 15 more
10.02 22:41:50 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at com.ShlobdonG.gMarry.Commands.onCommand(Commands.java:182) ~[?:?]
10.02 22:41:50 [Server] INFO Caused by: java.lang.ClassCastException: com.ShlobdonG.gMarry.Commands cannot be cast to org.bukkit.plugin.Plugin
10.02 22:41:50 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:574) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:675) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_111]
10.02 22:41:50 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_111]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1179) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1344) [spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650) ~[spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot_server.jar:git-Spigot-6854dee-dbf4ecf]
10.02 22:41:50 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'vmarry' in plugin gMarry v1.0
10.02 22:41:50 [Server] ERROR null

1 个答案:

答案 0 :(得分:1)

  

at com.ShlobdonG.gMarry.Commands.onCommand(Commands.java:182)

scheduleSyncDelayedTask((Plugin) this

  

引起:java.lang.ClassCastException:com.ShlobdonG.gMarry.Commands无法强制转换为org.bukkit.plugin.Plugin

有道理,对吗?

public class Commands可能无法扩展/实施Plugin