Development Assistance Errors With My Revenge Plugin

Discussion in 'Plugin Help/Development/Requests' started by TheGreenCreeper8, Jan 19, 2015.

Thread Status:
Not open for further replies.
  1. I'm having some problems with my plugin. I'm trying to make it so that people can take revenge on players that have killed them but its not working. I believe it is about either the Bukkit.broadcastMessage(ChatColor.GOLD + player.getName() + " is attempting to take revenge on " + player.getKiller().getName() + "!"); or the player.sendMessage(ChatColor.AQUA + "Your Target is: " + player.getKiller().getName() + "!"); lines of code as the error did not occur until i added it in. In-game I tried /revenge but it says 'an internal error has occurred while attempting to perform this command.' I am only new with plugin development as I have only made two plugins (including this one). I will paste the code to show what i did:
    Code:
    package me.greencreeper8;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class MainClass extends JavaPlugin {
    
        @Override
        public void onEnable() {
            new ListenerClass(this);
        }
       
        @Override
        public void onDisable() {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("killer") && sender instanceof Player) {
               
                Player player = (Player) sender;
               
                player.sendMessage(ChatColor.AQUA + "Your Killer Was: " + player.getKiller().getName() + "!");
               
                return true;
               
            } else if (cmd.getName().equalsIgnoreCase("revenge") && sender instanceof Player) {
               
                Player player = (Player) sender;
               
                player.sendMessage(ChatColor.AQUA + "Your Target is: " + player.getKiller().getName() + "!");
                PotionEffect speed = PotionEffectType.SPEED.createEffect(999999999, 3);
                    player.addPotionEffect(speed, true);
                    player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1));
                    player.setMaxHealth(10);
                    Bukkit.broadcastMessage(ChatColor.GOLD + player.getName() + " is attempting to take revenge on " + player.getKiller().getName() + "!");
                   
            } else if (cmd.getName().equalsIgnoreCase("unrevenge") && sender instanceof Player) {
               
                Player player = (Player) sender;
               
                player.sendMessage(ChatColor.AQUA + "Your Target is no longer: " + player.getKiller().getName() + "!");
                    player.removePotionEffect(PotionEffectType.SPEED);
                    player.setMaxHealth(20);
                    player.getInventory().removeItem(new ItemStack(Material.WOOD_SWORD));
                   
            return false;   
           
               
            }
            return false;
        }
    }
    any help appreciated!
    Thanks!
     
  2. Offline

    metmad22

    Please post the error you are having. Also did you register your commands in your plugin.yml?
     
  3. Offline

    pie_flavor

    @metmad22 Not necessary, I recognize this. @TheGreenCreeper8 The most common error in a bukkit plugin is the NullPointerException. Most people just look at the error, and freak out, assume it'll be complicated, and ask someone else to fix it. If you actually look at it, you'll see there's one line with your class in it, and the overall exception I am expecting will say NullPointerException. It simply means that a player has not killed them since the last server restart, and the player is null but you are attempting to perform functions on it. Simply put:
    Add these checks:
    Code:java
    1. if (player.getKiller() != null)
     
Thread Status:
Not open for further replies.

Share This Page