Solved Where did I go wrong?

Discussion in 'Plugin Development' started by 87pen, Dec 24, 2014.

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

    87pen

    Can Someone tell me where I wen't wrong. I get the item to drop but changing its name doesn't seem to work. (Really new to making plugins)



    Code:
    package me.kowagatte.HeadHunting;
    
    import java.util.logging.Logger;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Blaze;
    import org.bukkit.entity.Chicken;
    import org.bukkit.entity.Cow;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.Enderman;
    import org.bukkit.entity.IronGolem;
    import org.bukkit.entity.Pig;
    import org.bukkit.entity.PigZombie;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Skeleton;
    import org.bukkit.entity.Spider;
    import org.bukkit.entity.Zombie;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class HeadHunting extends JavaPlugin  implements Listener{
       
        public static Economy econ = null;
       
        @Override
        public void onEnable() {
            getLogger().info("<>>Head Hunting has been enabled<<>");
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults();
            if (!setupEconomy() ) {
                Logger getLogger;
                getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
        }
          //On Disable
          public void onDisable() {
            getLogger().info("<>>Head Hunting has been diabled<<>");
            saveConfig();
          }
         
            private boolean setupEconomy() {
                if (getServer().getPluginManager().getPlugin("Vault") == null) {
                    return false;
                }
                RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
                if (rsp == null) {
                    return false;
                }
                econ = rsp.getProvider();
                return econ != null;
            }
    
         
          @EventHandler
          public void onPlayerDeath(PlayerDeathEvent e){
            ItemStack playerhead = new ItemStack(Material.SKULL_ITEM, 1);
            Player killer = e.getEntity().getKiller();
            Player Deceased = e.getEntity().getPlayer();
            ItemMeta playerheadmeta = playerhead.getItemMeta();
            playerheadmeta.setDisplayName(Deceased.getName() + " Skull");
    
            e.getDrops().add(new ItemStack(Material.SKULL_ITEM, 1));
          }
          @EventHandler
          public void onEntityDeath(EntityDeathEvent e){
              if(e.getEntity() instanceof Zombie){
                  ItemStack zombiehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta zombieheadmeta = zombiehead.getItemMeta();
                  zombieheadmeta.setDisplayName("Zombie Skull");
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), zombiehead);
              }else if(e.getEntity() instanceof Skeleton){
                  ItemStack skelehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta skeleheadmeta = skelehead.getItemMeta();
                  skeleheadmeta.setDisplayName("Skeleton Skull");
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), skelehead);
              }else if(e.getEntity() instanceof Pig){
                  ItemStack pighead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta pigheadmeta = pighead.getItemMeta();
                  pigheadmeta.setDisplayName("Pig Skull");
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), pighead);
              }else if(e.getEntity() instanceof PigZombie){
                  ItemStack pigzombiehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta pigzombieheadmeta = pigzombiehead.getItemMeta();
                  pigzombieheadmeta.setDisplayName("PigZombie Skull");
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), pigzombiehead);
              }else if(e.getEntity() instanceof Cow){
                  ItemStack cowhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta cowheadmeta = cowhead.getItemMeta();
                  cowheadmeta.setDisplayName("Cow Skull"); 
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), cowhead);
              }else if(e.getEntity() instanceof Chicken){
                  ItemStack chickenhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta chickenheadmeta = chickenhead.getItemMeta();
                  chickenheadmeta.setDisplayName("Chicken Skull"); 
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), chickenhead);
              }else if(e.getEntity() instanceof Creeper){
                  ItemStack creeperhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta creeperheadmeta = creeperhead.getItemMeta();
                  creeperheadmeta.setDisplayName("Creeper Skull"); 
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), creeperhead);
              }else if(e.getEntity() instanceof Enderman){
                  ItemStack endermanhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta endermanheadmeta = endermanhead.getItemMeta();
                  endermanheadmeta.setDisplayName("Enderman Skull"); 
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), endermanhead); 
              }else if(e.getEntity() instanceof Spider){
                  ItemStack spiderhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta spiderheadmeta = spiderhead.getItemMeta();
                  spiderheadmeta.setDisplayName("Spider Skull"); 
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), spiderhead); 
              }else if(e.getEntity() instanceof Blaze){
                  ItemStack blazehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta blazeheadmeta = blazehead.getItemMeta();
                  blazeheadmeta.setDisplayName("Blaze Skull"); 
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), blazehead); 
              }else if(e.getEntity() instanceof IronGolem){
                  ItemStack ironhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta ironheadmeta = ironhead.getItemMeta();
                  ironheadmeta.setDisplayName("IronGolem Skull"); 
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), ironhead); 
              }
          }
          public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
          {
            if (cmd.getName().equalsIgnoreCase("sellhead") || cmd.getName().equalsIgnoreCase("sh")) {
                ItemStack head = new ItemStack(Material.SKULL_ITEM, 1);
                Player p = (Player)sender;
                if(p.getItemInHand().getType().equals(head)){
                    ItemStack nothing = new ItemStack(Material.AIR, 1);
                    ItemMeta Meta = head.getItemMeta();
                    String name = p.getItemInHand().getItemMeta().getDisplayName();
                    if(name.equals("Zombie Skull")){
                    EconomyResponse r = econ.depositPlayer(p.getName(), 25);
                    if(r.transactionSuccess()){
                        p.setItemInHand(nothing);
                        p.sendMessage("Transaction Successful");
                    }else{
                        p.sendMessage("Transaction UnSuccessful");
                    }
                   
                    }else if(name.equals("Skeleton Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 35);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Pig Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("PigZombie Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 125);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Cow Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Chicken Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("IronGolem Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 150);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Creeper Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 75);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Enderman Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 100);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Spider Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 45);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("blaze Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 80);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else{
                        EconomyResponse r = econ.depositPlayer(p.getName(), 50);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }
                }else{
                    p.sendMessage("Please Hold a Skull.");
                }
    
              }
            return false;
          }
    }
     
  2. Offline

    WampyCakes

    You didn't make it so that the ItemStack uses the ItemMeta
    Use
    Code:
    playerhead.setItemMeta(playerheadmeta);
     
    Konato_K likes this.
  3. Offline

    SuperOriginal

    If a player dies for some reason other than a player, you will get an NPE. (Check if killer is null)

    You don't need to state when your plugin is enabled/disabled. Bukkit does that.

    Check if CommandSender is player before casting.
     
  4. Offline

    87pen

    Thanks that fixed the Name problem but my command doesn't work.

    I want the player to drop a skull even if hes killed by a mob or environmental causes. :/ thanks tho!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  5. Offline

    SuperOriginal

    Put a null check for iteminhand in case they have nothing. The command isn't making it past the first Boolean because you're comparing an itemstack to getType() which is a material.

    Edit: getKiller() returns a player, maybe you could use getLastDamageCause()? Not completely sure at the moment.
     
  6. Offline

    87pen

    Like this?
    Code:
          public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
          {
            if (cmd.getName().equalsIgnoreCase("sellhead") || cmd.getName().equalsIgnoreCase("sh")) {
                ItemStack head = new ItemStack(Material.SKULL_ITEM, 1);
                Player p = (Player)sender;
                boolean empty = p.getItemInHand() == null;
                if(!empty){
                if(p.getItemInHand().equals(head)){
     
  7. Offline

    SuperOriginal

    You could shorten the "empty" statements to simply, if(p.getItemInHand() != null), but yes, you get the concept.
     
  8. Offline

    87pen

    Still doesn't work, Wondering if its because of plugin.yml:
    Code:
    name: HeadHunting
    main: me.kowagatte.HeadHunting.HeadHunting
    version: 2.5
    commands:
       sellhead:
          description: Sell a Skull
          usage: /sellhead
          permission:
          permission-message: You can't do that!
       sh:
          description: Sell a Skull
          usage: /sh
          permission:
          permission-message: You can't do that!
     
  9. Offline

    SuperOriginal

    @87pen I can't tell because of the ruined indentation, but is there an exception in console? If there isn't then it's a logic error. If this is the case you can insert debug messages throughout your code and then you will visibly see where your code reaches and you can isolate the problem.
     
  10. Offline

    87pen

    Nothing shows up in the console but in-game what shows up is the usage and description of the command.
     
  11. Offline

    nverdier

    @87pen That means that the onCommand returned false. Add else statements after the if statements.
     
  12. Offline

    SuperOriginal

    Return true instead of false if you want to remove the usage messages. According to this, you need a value in the "permission" section of your plugin.yml, you left it blank. Try the message debugging I mentioned.
     
  13. Offline

    nverdier

    @SuperOriginal It's not required. You don't need to return true, just add else statements, the you can send messages to the player is a problem occurred etc
     
  14. Offline

    SuperOriginal

    @nverdier When did I say it was required? I just prefer returning true and handling my own error/usage messages.
     
  15. Offline

    nverdier

    Sorry, thought it was implied.

    But if you just add else statements you can use messages based on what happened.
     
    SuperOriginal likes this.
  16. Offline

    87pen

    I changed it to return true, And instead of it saying the usage and desc when I do /sellhead it only says the desc
     
  17. Offline

    nverdier

    Did you add else statements?
     
  18. Offline

    87pen

    where do I add them?
     
  19. Offline

    nverdier

    After the if statements.
     
  20. Offline

    87pen

    Still only saying desc of command;
    Code:
    package me.kowagatte.HeadHunting;
    
    import java.util.logging.Logger;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Blaze;
    import org.bukkit.entity.Chicken;
    import org.bukkit.entity.Cow;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.Enderman;
    import org.bukkit.entity.IronGolem;
    import org.bukkit.entity.Pig;
    import org.bukkit.entity.PigZombie;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Skeleton;
    import org.bukkit.entity.Spider;
    import org.bukkit.entity.Zombie;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class HeadHunting extends JavaPlugin  implements Listener{
       
        public static Economy econ = null;
       
        @Override
        public void onEnable() {
            getLogger().info("<>>Head Hunting has been enabled<<>");
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults();
            if (!setupEconomy() ) {
                Logger getLogger;
                getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
        }
          //On Disable
          public void onDisable() {
            getLogger().info("<>>Head Hunting has been diabled<<>");
            saveConfig();
          }
         
            private boolean setupEconomy() {
                if (getServer().getPluginManager().getPlugin("Vault") == null) {
                    return false;
                }
                RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
                if (rsp == null) {
                    return false;
                }
                econ = rsp.getProvider();
                return econ != null;
            }
    
         
          @EventHandler
          public void onPlayerDeath(PlayerDeathEvent e){
            ItemStack playerhead = new ItemStack(Material.SKULL_ITEM, 1);
            Player killer = e.getEntity().getKiller();
            Player Deceased = e.getEntity().getPlayer();
            ItemMeta playerheadmeta = playerhead.getItemMeta();
            playerheadmeta.setDisplayName(Deceased.getName() + "'s Skull");
            playerhead.setItemMeta(playerheadmeta);
            e.getDrops().add(playerhead);
          }
          @EventHandler
          public void onEntityDeath(EntityDeathEvent e){
              if(e.getEntity() instanceof Zombie){
                  ItemStack zombiehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta zombieheadmeta = zombiehead.getItemMeta();
                  zombieheadmeta.setDisplayName("Zombie Skull");
                  zombiehead.setItemMeta(zombieheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), zombiehead);
              }else if(e.getEntity() instanceof Skeleton){
                  ItemStack skelehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta skeleheadmeta = skelehead.getItemMeta();
                  skeleheadmeta.setDisplayName("Skeleton Skull");
                  skelehead.setItemMeta(skeleheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), skelehead);
              }else if(e.getEntity() instanceof Pig){
                  ItemStack pighead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta pigheadmeta = pighead.getItemMeta();
                  pigheadmeta.setDisplayName("Pig Skull");
                  pighead.setItemMeta(pigheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), pighead);
              }else if(e.getEntity() instanceof PigZombie){
                  ItemStack pigzombiehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta pigzombieheadmeta = pigzombiehead.getItemMeta();
                  pigzombieheadmeta.setDisplayName("PigZombie Skull");
                  pigzombiehead.setItemMeta(pigzombieheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), pigzombiehead);
              }else if(e.getEntity() instanceof Cow){
                  ItemStack cowhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta cowheadmeta = cowhead.getItemMeta();
                  cowheadmeta.setDisplayName("Cow Skull"); 
                  cowhead.setItemMeta(cowheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), cowhead);
              }else if(e.getEntity() instanceof Chicken){
                  ItemStack chickenhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta chickenheadmeta = chickenhead.getItemMeta();
                  chickenheadmeta.setDisplayName("Chicken Skull"); 
                  chickenhead.setItemMeta(chickenheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), chickenhead);
              }else if(e.getEntity() instanceof Creeper){
                  ItemStack creeperhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta creeperheadmeta = creeperhead.getItemMeta();
                  creeperheadmeta.setDisplayName("Creeper Skull");
                  creeperhead.setItemMeta(creeperheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), creeperhead);
              }else if(e.getEntity() instanceof Enderman){
                  ItemStack endermanhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta endermanheadmeta = endermanhead.getItemMeta();
                  endermanheadmeta.setDisplayName("Enderman Skull");
                  endermanhead.setItemMeta(endermanheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), endermanhead); 
              }else if(e.getEntity() instanceof Spider){
                  ItemStack spiderhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta spiderheadmeta = spiderhead.getItemMeta();
                  spiderheadmeta.setDisplayName("Spider Skull"); 
                  spiderhead.setItemMeta(spiderheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), spiderhead); 
              }else if(e.getEntity() instanceof Blaze){
                  ItemStack blazehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta blazeheadmeta = blazehead.getItemMeta();
                  blazeheadmeta.setDisplayName("Blaze Skull");
                  blazehead.setItemMeta(blazeheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), blazehead); 
              }else if(e.getEntity() instanceof IronGolem){
                  ItemStack ironhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta ironheadmeta = ironhead.getItemMeta();
                  ironheadmeta.setDisplayName("IronGolem Skull");
                  ironhead.setItemMeta(ironheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), ironhead); 
              }else{
                 
              }
          }
          public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
          {
            if (cmd.getName().equalsIgnoreCase("sellhead") || cmd.getName().equalsIgnoreCase("sh")) {
                ItemStack head = new ItemStack(Material.SKULL_ITEM, 1);
                Player p = (Player)sender;
                boolean empty = p.getItemInHand() == null;
                if(!empty){
                if(p.getItemInHand().equals(head)){
                    ItemStack nothing = new ItemStack(Material.AIR, 1);
                    ItemMeta Meta = head.getItemMeta();
                    String name = p.getItemInHand().getItemMeta().getDisplayName();
                    if(name.equals("Zombie Skull")){
                    EconomyResponse r = econ.depositPlayer(p.getName(), 25);
                    if(r.transactionSuccess()){
                        p.setItemInHand(nothing);
                        p.sendMessage("Transaction Successful");
                    }else{
                        p.sendMessage("Transaction UnSuccessful");
                    }
                   
                    }else if(name.equals("Skeleton Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 35);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Pig Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("PigZombie Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 125);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Cow Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Chicken Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("IronGolem Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 150);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Creeper Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 75);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Enderman Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 100);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Spider Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 45);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("blaze Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 80);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else{
                        EconomyResponse r = econ.depositPlayer(p.getName(), 50);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }
                }else{
                    p.sendMessage("Please Hold a Skull.");
                }
    
              }
          }else{
          }
            return true;
          }
    }
     
  21. Offline

    WampyCakes

    I think I found where you went wrong. Instead of using
    Code:
    cmd.getName.equalsIgnoreCase
    You should use
    Code:
    if(label.equaldsIgnoreCase("Your Command"));
    When I started coding bukkit plugins I did
    Code:
    cmd.equalsIgnoreCase
    and it didn't work.
    You should also do
    Code:
    return false;
    instead of true.
    And in your plugin.yml you need 4 spaces after the command and 6 spaces after description and stuff. DO NOT USE TAB!!!
    You didn't register the permissions under commands correctly though. For more information about plugin YAMLS look here: http://wiki.bukkit.org/Plugin_YAML
     
  22. Offline

    nverdier

    No, that is not good. Don't use label, use
    Code:
    cmd.getName().equalsIgnoreCase("blah") {
    //stuff
    }
    The plugin.yml is fine, there were no errors on startup... Yes, use return false, not return true.

    @87pen You don't have an else after if (!empty)
     
  23. Offline

    teej107

    Are you testing Cunningham's Law?
     
    Konato_K and nverdier like this.
  24. Offline

    nverdier

    So true :p
     
    teej107 likes this.
  25. Offline

    WampyCakes

    When I started making bukkit plugin I noticed
    Code:
    cmd.getName
    DOES NOT WORK. I had to use
    Code:
    label.equalsIgnoreCase
    For it to work. @87pen Don't listen to them, use
    Code:
    label.equalsIgnoreCase
     
  26. Offline

    SuperOriginal

    @WampyCakes Please tell me you're joking.... Please. Please.
     
    Konato_K likes this.
  27. Offline

    teej107

    @WampyCakes I can assure you that it does work and it is better to use Command.getName() for alias support

    @87pen You need to set the ItemStack's ItemMeta which you have not done.
     
  28. Offline

    SuperOriginal

    @teej107 He does in his updated code.
     
  29. Offline

    teej107

    @SuperOriginal Ah.
    for onCommand(), return true to show nothing, return false to show the usage.
     
  30. Offline

    87pen

    Still nothing, If you guys didn't notice I forgot to mention I'm using Vault as a depend.
    Code:
    package me.kowagatte.HeadHunting;
    
    import java.util.logging.Logger;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Blaze;
    import org.bukkit.entity.Chicken;
    import org.bukkit.entity.Cow;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.Enderman;
    import org.bukkit.entity.IronGolem;
    import org.bukkit.entity.Pig;
    import org.bukkit.entity.PigZombie;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Skeleton;
    import org.bukkit.entity.Spider;
    import org.bukkit.entity.Zombie;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class HeadHunting extends JavaPlugin  implements Listener{
       
        public static Economy econ = null;
       
        @Override
        public void onEnable() {
            getLogger().info("<>>Head Hunting has been enabled<<>");
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults();
            if (!setupEconomy() ) {
                Logger getLogger;
                getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
        }
          //On Disable
          public void onDisable() {
            getLogger().info("<>>Head Hunting has been diabled<<>");
            saveConfig();
          }
         
            private boolean setupEconomy() {
                if (getServer().getPluginManager().getPlugin("Vault") == null) {
                    return false;
                }
                RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
                if (rsp == null) {
                    return false;
                }
                econ = rsp.getProvider();
                return econ != null;
            }
    
         
          @EventHandler
          public void onPlayerDeath(PlayerDeathEvent e){
            ItemStack playerhead = new ItemStack(Material.SKULL_ITEM, 1);
            Player killer = e.getEntity().getKiller();
            Player Deceased = e.getEntity().getPlayer();
            ItemMeta playerheadmeta = playerhead.getItemMeta();
            playerheadmeta.setDisplayName(Deceased.getName() + "'s Skull");
            playerhead.setItemMeta(playerheadmeta);
            e.getDrops().add(playerhead);
          }
          @EventHandler
          public void onEntityDeath(EntityDeathEvent e){
              if(e.getEntity() instanceof Zombie){
                  ItemStack zombiehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta zombieheadmeta = zombiehead.getItemMeta();
                  zombieheadmeta.setDisplayName("Zombie Skull");
                  zombiehead.setItemMeta(zombieheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), zombiehead);
              }else if(e.getEntity() instanceof Skeleton){
                  ItemStack skelehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta skeleheadmeta = skelehead.getItemMeta();
                  skeleheadmeta.setDisplayName("Skeleton Skull");
                  skelehead.setItemMeta(skeleheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), skelehead);
              }else if(e.getEntity() instanceof Pig){
                  ItemStack pighead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta pigheadmeta = pighead.getItemMeta();
                  pigheadmeta.setDisplayName("Pig Skull");
                  pighead.setItemMeta(pigheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), pighead);
              }else if(e.getEntity() instanceof PigZombie){
                  ItemStack pigzombiehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta pigzombieheadmeta = pigzombiehead.getItemMeta();
                  pigzombieheadmeta.setDisplayName("PigZombie Skull");
                  pigzombiehead.setItemMeta(pigzombieheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), pigzombiehead);
              }else if(e.getEntity() instanceof Cow){
                  ItemStack cowhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta cowheadmeta = cowhead.getItemMeta();
                  cowheadmeta.setDisplayName("Cow Skull"); 
                  cowhead.setItemMeta(cowheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), cowhead);
              }else if(e.getEntity() instanceof Chicken){
                  ItemStack chickenhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta chickenheadmeta = chickenhead.getItemMeta();
                  chickenheadmeta.setDisplayName("Chicken Skull"); 
                  chickenhead.setItemMeta(chickenheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), chickenhead);
              }else if(e.getEntity() instanceof Creeper){
                  ItemStack creeperhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta creeperheadmeta = creeperhead.getItemMeta();
                  creeperheadmeta.setDisplayName("Creeper Skull");
                  creeperhead.setItemMeta(creeperheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), creeperhead);
              }else if(e.getEntity() instanceof Enderman){
                  ItemStack endermanhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta endermanheadmeta = endermanhead.getItemMeta();
                  endermanheadmeta.setDisplayName("Enderman Skull");
                  endermanhead.setItemMeta(endermanheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), endermanhead); 
              }else if(e.getEntity() instanceof Spider){
                  ItemStack spiderhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta spiderheadmeta = spiderhead.getItemMeta();
                  spiderheadmeta.setDisplayName("Spider Skull"); 
                  spiderhead.setItemMeta(spiderheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), spiderhead); 
              }else if(e.getEntity() instanceof Blaze){
                  ItemStack blazehead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta blazeheadmeta = blazehead.getItemMeta();
                  blazeheadmeta.setDisplayName("Blaze Skull");
                  blazehead.setItemMeta(blazeheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), blazehead); 
              }else if(e.getEntity() instanceof IronGolem){
                  ItemStack ironhead = new ItemStack(Material.SKULL_ITEM, 1);
                  ItemMeta ironheadmeta = ironhead.getItemMeta();
                  ironheadmeta.setDisplayName("IronGolem Skull");
                  ironhead.setItemMeta(ironheadmeta);
                  e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), ironhead); 
              }else{
                 
              }
          }
          public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
          {
            if (cmd.getName().equalsIgnoreCase("sellhead") || cmd.getName().equalsIgnoreCase("sh")) {
                ItemStack head = new ItemStack(Material.SKULL_ITEM, 1);
                Player p = (Player)sender;
                boolean empty = p.getItemInHand() == null;
                if(!empty){
                if(p.getItemInHand().equals(head)){
                    ItemStack nothing = new ItemStack(Material.AIR, 1);
                    ItemMeta Meta = head.getItemMeta();
                    String name = p.getItemInHand().getItemMeta().getDisplayName();
                    if(name.equals("Zombie Skull")){
                    EconomyResponse r = econ.depositPlayer(p.getName(), 25);
                    if(r.transactionSuccess()){
                        p.setItemInHand(nothing);
                        p.sendMessage("Transaction Successful");
                    }else{
                        p.sendMessage("Transaction UnSuccessful");
                    }
                   
                    }else if(name.equals("Skeleton Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 35);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Pig Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("PigZombie Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 125);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Cow Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Chicken Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 5);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("IronGolem Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 150);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Creeper Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 75);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Enderman Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 100);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("Spider Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 45);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else if(name.equals("blaze Skull")){
                        EconomyResponse r = econ.depositPlayer(p.getName(), 80);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }else{
                        EconomyResponse r = econ.depositPlayer(p.getName(), 50);
                        if(r.transactionSuccess()){
                            p.setItemInHand(nothing);
                            p.sendMessage("Transaction Successful");
                        }else{
                            p.sendMessage("Transaction UnSuccessful");
                        }
                    }
                }else{
                    p.sendMessage("Please Hold a Skull.");
                }
    
              }else{
          }
            return true;
          }else{
          }
            return false;
    }
    }
    Code:
    name: HeadHunting
    main: me.kowagatte.HeadHunting.HeadHunting
    version: 2.5
    depend: [Vault]
    commands:
       sellhead:
          description: Sell a Skull
          usage: /sellhead
          aliases: [sh]
     
Thread Status:
Not open for further replies.

Share This Page