Helpme I Got error with my code

Discussion in 'Spigot Plugin Help' started by Raymart, May 14, 2015.

  1. Code (Text):
    package me.raymart.plugin;

    import java.util.logging.Logger;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Main plugin;
       
        public void onEnable() {
            PluginDescriptionFile f = this.getDescription();
            getConfig().options().copyDefaults(true);
            saveConfig();
            this.logger.info("Enabling " + f.getName() + " v" + f.getVersion());
        }
       
        public void onDisable() {
            PluginDescriptionFile f = this.getDescription();
            this.logger.info("Disabling " + f.getName() + " v" + f.getVersion());
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player p = (Player) sender;
            String prefix = this.getConfig().getString("Prefix").replaceAll("&", "§");
            String noperm = this.getConfig().getString("nopermmsg").replaceAll("&", "§").replace("<player>", p.getName());
            if(cmd.getName().equalsIgnoreCase("sendme") || (p.hasPermission("sendme.command"))) {
                p.sendMessage(ChatColor.GOLD + "Sent");
            }else {
                p.sendMessage(prefix + noperm);
            }
            if(cmd.getName().equalsIgnoreCase("heal") || (p.hasPermission("heal.command"))) {
                p.setHealth(20);
                p.setFoodLevel(20);
                p.setFireTicks(0);
                p.sendMessage(ChatColor.GREEN + "healed");
            }else {
                p.sendMessage(prefix + noperm);
            }
            if(cmd.getName().equalsIgnoreCase("kill") || (p.hasPermission("kill.command"))) {
                p.setHealth(0);
                p.sendMessage(ChatColor.DARK_RED + "killed");
            }else {
                p.sendMessage(prefix + noperm);
            }
            if(cmd.getName().equalsIgnoreCase("feed") || (p.hasPermission("feed.command"))) {
                p.setFoodLevel(20);
                p.sendMessage(ChatColor.GREEN + "You are no longer hungry");
            }else {
                p.sendMessage(prefix + noperm);
            }
            if(cmd.getName().equalsIgnoreCase("blow") || (p.hasPermission("blow.command"))) {
                p.setFireTicks(0);
            }else {
                p.sendMessage(prefix + noperm);
            }
            if(cmd.getName().equalsIgnoreCase("dontpick") || (p.hasPermission("dontpick.command"))) {
                p.setCanPickupItems(false);
                p.sendMessage(ChatColor.DARK_RED + "You can't pick items now");
            }else {
                p.sendMessage(prefix + noperm);
            }
            if(cmd.getName().equalsIgnoreCase("picknow") || (p.hasPermission("pick.command"))) {
                p.setCanPickupItems(true);
                p.sendMessage(ChatColor.GREEN + "You can pick items now");
            }else {
                p.sendMessage(prefix + noperm);
            }
            if(cmd.getName().equalsIgnoreCase("hat") || (p.hasPermission("hat.command"))) {
                p.getInventory().setHeldItemSlot(1);
            }else {
                p.sendMessage(prefix + noperm);
            }
            return false;
        }

    }
     
    help me I got error with this my code :D whats the wrong ? thanks
     
  2. Posting the error log will help :)
     
  3. @omon23 here it goes :D
    Code (Text):
    [14:58:40 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'kill
    ' in plugin Commands v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    9) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:544) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:932) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
    Caused by: java.lang.NullPointerException
            at me.raymart.plugin.Main.onCommand(Main.java:30) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2992jnks]
     
  4. Your config doesn't contain the string value for "Prefix"
     
  5. It has but oh I founded it out thanks :D its prefix without upercase .....................