Help me with config...

Discussion in 'Spigot Plugin Development' started by TozyMC, Jun 7, 2018.

  1. Code (Text):
    [08:04:47 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'clearchat' in plugin ChatPro v1.0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_171]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_171]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
    Caused by: java.lang.NullPointerException
            at me.tozymc.chatpro.cmds.ClearChatCmd.onCommand(ClearChatCmd.java:24) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            ... 15 more
    Code (Java):
    package me.tozymc.chatpro.cmds;

    import me.tozymc.chatpro.ChatPro;
    import me.tozymc.chatpro.utils.Utils;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import static me.tozymc.chatpro.utils.Utils.replace;
    import static me.tozymc.chatpro.utils.Utils.sendHelp;

    public class ClearChatCmd implements CommandExecutor {
        private ChatPro plugin;

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("clearchat")) {
                if (args.length == 0) {
                    if (Utils.hasPerms("clear", sender)) {
                        for (int i = 0; i <= 120; i++) {
                            sender.sendMessage("");
                        }
                        sender.sendMessage(plugin.getConfig().getString("Message.ClearChat"));
                    }
                }
                if (args.length == 1) {
                    if ((args[0].equalsIgnoreCase("all")) && (Utils.hasPerms("admin", sender))) {
                        for (Player sender1 : Bukkit.getOnlinePlayers()) {
                            for (int i = 0; i <= 120; i++) {
                                sender1.sendMessage("");
                            }
                            sender1.sendMessage(replace(plugin.getConfig().getString("Message.ClearAllChat")));
                        }
                    }
                } else {
                    sendHelp(sender);
                }
            }
            return true;
        }
    }
     
    Code (Java):
    package me.tozymc.chatpro;

    import me.tozymc.chatpro.cmds.ChatProCmd;
    import me.tozymc.chatpro.cmds.ClearChatCmd;
    import me.tozymc.chatpro.listeners.ChatLock;
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;

    public final class ChatPro extends JavaPlugin {
        public boolean chat;

        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(new ChatLock(), this);
            this.getConfig().options().copyDefaults(true);
            this.getConfig().addDefault("Chat", true);
            this.getConfig().addDefault("Prefix", "&3&lChatPro &7ยป ");
            this.getConfig().addDefault("Message.NoPerms", "&cYou not have permission to do this!");
            this.getConfig().addDefault("Message.ChatLock", "Chat has &c&lLOCK&7!");
            this.getConfig().addDefault("Message.ChatUnLock", "Chat has &a&lUNLOCK&7!");
            this.getConfig().addDefault("Message.ChatLocked", "&cChat has locked!");
            this.getConfig().addDefault("Message.ClearChat", "Chat has cleaned!");
            this.getConfig().addDefault("Message.ClearAllChat", "All chat has cleaned!");
            this.saveConfig();
            getCommand("chatpro").setExecutor(new ChatProCmd());
            getCommand("clearchat").setExecutor(new ClearChatCmd());

        }

        public void onDisable() {
        }
    }

    I have encountered the above error, I spent all day fixing the error, but no way. I think it's related to config! Hope everybody help please! Thank you!

    Spigot-api Version: 1.8.8
     
  2. private ChatPro plugin = ChatPro.getPlugin(ChatPro.class);

    The reason that you are getting the error is because your plugin instance is null.
     
  3. Yes! Thank you very much!