Minecraft Console Error. Please Help!

Discussion in 'Spigot Plugin Development' started by AlGrande, Jun 6, 2015.

  1. Hello
    I made a Plugin and it works fine ingame. But if I try to execute a command from my Plugin in console it always shows an error(in Command blocks nothing happens).
    Do I have to code my plugin different than normal so it works for console? My Plugin is "FakeChat". You can decompile it online if you need the full code.
    Thank You!
     
    #1 AlGrande, Jun 6, 2015
    Last edited: Jun 6, 2015
  2. Can just send the code?
     
  3. Code (Text):
    /*
    * Decompiled with CFR 0_101.
    *
    * Could not load the following classes:
    *  org.bukkit.Bukkit
    *  org.bukkit.ChatColor
    *  org.bukkit.Server
    *  org.bukkit.command.Command
    *  org.bukkit.command.CommandExecutor
    *  org.bukkit.command.CommandSender
    *  org.bukkit.command.PluginCommand
    *  org.bukkit.entity.Player
    *  org.bukkit.plugin.java.JavaPlugin
    */
    package me.AlGrande.main;

    import java.io.PrintStream;
    import java.util.Collection;
    import me.AlGrande.main.FakeJoin;
    import me.AlGrande.main.FakeLeave;
    import me.AlGrande.main.FakeMessage;
    import me.AlGrande.main.Fakeban;
    import me.AlGrande.main.fakedeop;
    import me.AlGrande.main.fakeop;
    import me.AlGrande.main.spam;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.PluginCommand;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main
    extends JavaPlugin {
        public void onEnable() {
            System.out.println("Fakechat 1.2 by AlGrande has been activated!");
            this.getCommand("fakemessage").setExecutor((CommandExecutor)new FakeMessage(this));
            this.getCommand("fm").setExecutor((CommandExecutor)new FakeMessage(this));
            this.getCommand("fakeban").setExecutor((CommandExecutor)new Fakeban(this));
            this.getCommand("fakejoin").setExecutor((CommandExecutor)new FakeJoin(this));
            this.getCommand("fakeleave").setExecutor((CommandExecutor)new FakeLeave(this));
            this.getCommand("fakeop").setExecutor((CommandExecutor)new fakeop(this));
            this.getCommand("fakedeop").setExecutor((CommandExecutor)new fakedeop(this));
            this.getCommand("spam").setExecutor((CommandExecutor)new spam(this));
        }

        public void onDisable() {
            System.out.println("Fakechat 1.2 by AlGrande has been deactivated!");
        }

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player)sender;
            if (!sender.hasPermission("fakechat.use")) {
                sender.sendMessage((Object)ChatColor.DARK_RED + "You need the permission fakechat.use!");
                return true;
            }
            if (sender instanceof Player) {
                Object arg;
                String ChatMessage;
                int i;
                if (label.equalsIgnoreCase("fakechat")) {
                    if (args.length == 0) {
                        sender.sendMessage((Object)ChatColor.RED + "/fakechat [Player/*(for everyone)] [Message]");
                        return true;
                    }
                    if (args.length != 1) {
                        ChatMessage = "";
                        for (i = 1; i < args.length; ++i) {
                            arg = String.valueOf(args[i]) + " ";
                            ChatMessage = String.valueOf(ChatMessage) + (String)arg;
                        }
                        if (args[0].equals("*")) {
                            for (Player all : this.getServer().getOnlinePlayers()) {
                                all.chat(ChatMessage);
                            }
                            player.sendMessage((Object)ChatColor.GREEN + "You made everyone to say something!");
                            return true;
                        }
                        if (Bukkit.getServer().getPlayer(args[0]) != null) {
                            Player target = Bukkit.getServer().getPlayer(args[0]);
                            target.chat(ChatMessage);
                            player.sendMessage((Object)ChatColor.GREEN + "You made " + target.getDisplayName() + (Object)ChatColor.GREEN + " to say something!");
                            return true;
                        }
                        player.sendMessage((Object)ChatColor.RED + "Player not found!");
                    } else {
                        player.sendMessage((Object)ChatColor.RED + "Too much or not enough arguments!");
                        return false;
                    }
                }
                if (label.equalsIgnoreCase("fc")) {
                    if (args.length == 0) {
                        sender.sendMessage((Object)ChatColor.RED + "/fc [Player/*(for everyone)] [Message]");
                        return true;
                    }
                    if (args.length != 1) {
                        ChatMessage = "";
                        for (i = 1; i < args.length; ++i) {
                            arg = String.valueOf(args[i]) + " ";
                            ChatMessage = String.valueOf(ChatMessage) + (String)arg;
                        }
                        if (args[0].equals("*")) {
                            for (Player all : this.getServer().getOnlinePlayers()) {
                                all.chat(ChatMessage);
                            }
                            player.sendMessage((Object)ChatColor.GREEN + "You made everyone to say something!");
                            return true;
                        }
                        if (Bukkit.getServer().getPlayer(args[0]) != null) {
                            Player target = Bukkit.getServer().getPlayer(args[0]);
                            target.chat(ChatMessage);
                            player.sendMessage((Object)ChatColor.GREEN + "You made " + target.getDisplayName() + (Object)ChatColor.GREEN + " to say something!");
                            return true;
                        }
                        player.sendMessage((Object)ChatColor.RED + "Player not found!");
                    } else {
                        player.sendMessage((Object)ChatColor.RED + "Too much or not enough arguments!");
                        return false;
                    }
                }
            }
            return false;
        }
    }
     
  4. Are you getting a ClassCastException? Your classes with the commands in it should implement CommandExecutor, unless it's the class that extends JavaPlugin.

    You have:
    Code (Text):
    this.getCommand("fakemessage").setExecutor((CommandExecutor)new FakeMessage(this));
    Remove the (CommandExecutor) and make FakeMessage implement CommandExecutor.
     
  5. Code (Text):
    public class FakeMessage
    implements CommandExecutor {
        public FakeMessage(main main) {
        }
    I get the error with /fakechat too and its in the Main class. I also implemented Commandexecutor in the other classes. But I'll remove the (CommandExecutor). Im currently on the mobile phone so I'll try it later.
     
  6. Yeah the problem is probably because you registered your command wrong.
     
  7. I'll remove the (commandExecutor) later. But /fakechat should work because it's in the Main.java. But it doesn't.
     
  8. You cant cast console sender to Player. ;)
     
    • Like Like x 2
    • Agree Agree x 1
  9. Thank You!
    So I have to put the console Commando in:
    Code (Text):
    if(!(player instanceof sender))
        {
    }
    But what should I write instead of
    Code (Text):
    Player player = (Player)sender;
     
  10. Code (Text):
    Player player = (Player)sender;
    That is fine
     
  11. I can use
    Player player = (Player)sender;
    for the Console too?
    BillyGalbreath said:
     
  12. sender.sendMessage() works.

    So, if there is no need for you to have a "player" at all, you just leave out the casting line and just use sender instead. If you require a player, then you have to tell console (sender) that the command requires a player and then return true to prevent the command from running.
     
    • Like Like x 1
  13. Thank You! It works!