Solved Weird command glitch.

Discussion in 'Plugin Help/Development/Requests' started by HighOnSwiftness, Aug 4, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    So, I made a quick op and deop command, with neither working.. just need some help.

    [04:23:02 INFO]: _eGL issued server command: /deop
    [04:23:02 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'deop
    ' in plugin ExEssentials v0.1
            at org.bukkit.command.PluginCommand.execute( ~[cra
            at org.bukkit.command.SimpleCommandMap.dispatch(
    0) ~[craftbukkit.jar:git-Bukkit-00eba53]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe ~[craftbukkit.jar:git-Bukkit-00eba53]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon [craftbukkit.jar:git-Bukkit-00eba53]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(
    :919) [craftbukkit.jar:git-Bukkit-00eba53]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:37) [craft
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:9) [craftb
            at [cra
            at java.util.concurrent.Executors$ Source) [
            at Source) [?:1.8.0_51]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(
    43) [craftbukkit.jar:git-Bukkit-00eba53]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(
    84) [craftbukkit.jar:git-Bukkit-00eba53]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(
    98) [craftbukkit.jar:git-Bukkit-00eba53]
    :506) [craftbukkit.jar:git-Bukkit-00eba53]
            at Source) [?:1.8.0_51]
    Caused by: java.lang.NullPointerException
            at me.essentials.commands.DeOpCommand.onCommand( ~[?
            at org.bukkit.command.PluginCommand.execute( ~[cra
            ... 14 more
    That's the error, here's my deopcommand class.

    package me.essentials.commands;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import me.essentials.Main;
    public class DeOpCommand implements CommandExecutor {
        public static Main plugin;
        public boolean onCommand(CommandSender snd, Command cmd, String lbl, String[] args){
                if(snd instanceof Player){
                    Player p = (Player) snd;
                    if(args.length == 0){
                    }else if(args.length == 1){
                            Player target = (Player) plugin.getServer().getOfflinePlayer(args[0]);
                            if(target == null){
                                p.sendMessage(ChatColor.DARK_RED + "Player does not exist!");
                                p.sendMessage(ChatColor.GRAY + "DeOpped " + ChatColor.GREEN + target.getName() + ChatColor.GRAY + ".");
                                target.sendMessage(ChatColor.GRAY + "You've been deopped.");
            return false;
    And, here's my main class.

    package me.essentials;
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.event.Listener;
    import me.essentials.commands.DeOpCommand;
    import me.essentials.commands.OpCommand;
    public class Main extends JavaPlugin implements Listener {
        public static Main plugin;
        public void onEnable(){
            Logger log = Logger.getLogger("Minecraft");
  "Essentials: Enabled, hello!");
            getCommand("op").setExecutor(new OpCommand());
            getCommand("deop").setExecutor(new DeOpCommand());
        public void onDisable(){
            Logger log = Logger.getLogger("Minecraft");
  "Essentials: Disabled, goodbye!");
        public String wrongargs = ChatColor.DARK_RED + "Wrong use of arguments!";
        public String nopermission = ChatColor.DARK_RED + "You do not have permission for this command!";
        public String playersonly = ChatColor.DARK_RED + "Only players may use this command!";
    Thank you! :)
  2. @HighOnSwiftness
    You never initialize the "plugin" field in your CommandExecutor, so it throws an NPE
  3. Moved to Bukkit Alternates

    That code...
    Ok, so before you even continue making commands please please fix the bad practices.
    1. Why all the empty else's?
    2. plugin is null because you never initialized it, pass the instance through the constructor.
    3. Don't use java's logger use Bukkit's
    4. Why is plugin static in the main class?
    5. No need for enable and disable messages. Bukkit does it for you.
    6. Your onDisable will now be empty, you can remove it.
    7. Why implement Listener and never use it?
  4. Offline


    Thanks everyone! I'm so tired and I completely forgot to do this.. thank you!
Thread Status:
Not open for further replies.

Share This Page