HeadHunting Plugin

Discussion in 'Plugin Requests' started by OperationVaas, Nov 28, 2014.

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

    OperationVaas

    Plugin category: Mechanics

    Suggested name: HeadHunting

    What I want: Kill someone, and then their head will drop. When you pick up their head it will say a value on the bottom, the value would be determined by like some sort of stat. You could sell the head for in game currency.

    Ideas for commands: /hh reload, /hh spawnhead <name>

    Ideas for permissions: Not sure

    When I'd like it by: As soon as possible.
     
  2. Offline

    drpk

    OperationVaas "determined by like some sort of stat" gonna need more information than that.
     
  3. Offline

    OperationVaas

    I mean determined by like kills, or how much money they have.
     
    Sil3nt_Aassassin likes this.
  4. Can someone do this?
     
  5. Offline

    Jayke_

    You need to decide what "stat" exactly is going to create this value.
     
  6. Offline

    cucci0

    @Jayke_ I think he means if you got my head (cucci0) and i have killed 50 players the head is worth $2000. But if i die 50 times the head will be worth $0 because i have 50 kills and 50 deaths. It's almost as a KDR in Call of Duty etc.
     
    Sil3nt_Aassassin likes this.
  7. Offline

    bmckalip

    I'll start on this tonight, I think this is a neat idea.
    EDIT:
    completed rough functionality. no frills yet.
    http://dev.bukkit.org/bukkit-plugins/headhunting/
    https://www.dropbox.com/s/wmpmp85rbq18cpz/Headhunting.jar?dl=0

    source:
    Code:
    package bmckalip.HeadHunting;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.SkullType;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.Configuration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.SkullMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class HeadHunting extends JavaPlugin implements Listener {
        Configuration config = getConfig();
        ItemStack head = new ItemStack(Material.SKULL_ITEM, 1,(short)SkullType.PLAYER.ordinal());
    
        public void onEnable(){
            getConfig().options().copyDefaults(true);
            saveConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
    
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
            if(!(sender instanceof Player)){
                sender.sendMessage(ChatColor.RED + "Only players can use commands");
                return true;
            }
            if(command.getName().equalsIgnoreCase("collectbounty") && args.length == 1){
                if(args[0].equalsIgnoreCase("hand")){
                    sender.sendMessage(redeem("hand", (Player)sender));
                }else if(args[0].equalsIgnoreCase("all")){
                    sender.sendMessage(redeem("all", (Player)sender));
                }
                return true;
            }else{
                sender.sendMessage("Usage: /CollectBounty <hand/all>");
            }
            return true;
        }
    
        @EventHandler
        public void awardBounty(PlayerDeathEvent event){
            String killer = event.getEntity().getKiller().getName();
            String victim = event.getEntity().getPlayer().getName();
            Double value = config.getDouble("KillValue") * getKD(victim);
       
            if(killer != null){
                addDeath(victim);
                addKill(killer);
           
                SkullMeta meta = (SkullMeta) head.getItemMeta();
                meta.setOwner(victim);
                meta.setDisplayName(ChatColor.WHITE + victim + "'s head!" + ChatColor.RED + " [$" + value + "]");
                head.setItemMeta(meta);
           
                event.getDrops().add(head);
            }
        }
    
        @EventHandler
        public void addPlayerToBountyList(PlayerJoinEvent event){
            Player player = event.getPlayer();
            config.set("Players." + player.getName(), null);
            config.set("Players." + player.getName() + ".Kills", 0);
            config.set("Players." + player.getName() + ".Deaths", 0);
            saveConfig();
        }
    
        public void addKill(String player){
            config.set("Players." + player + ".Kills", config.getInt("Players." + player + ".Kills") + 1);
            saveConfig();
        }
    
        public void addDeath(String player){
            config.set("Players." + player + ".Deaths", config.getInt("Players." + player + ".Deaths") + 1);
            saveConfig();
        }
    
        public double getKD(String player){
            int kills = config.getInt("Players." + player + ".Kills");
            int deaths = config.getInt("Players." + player + ".Deaths");
            double KD;
            if(deaths != 0){
                KD = kills / deaths;
            }else{
                KD = kills;
            }
            return KD;
        }
    
        public String redeem(String type, Player player){
            ItemStack item = player.getInventory().getItemInHand();
            if(item.getAmount() > 1){
            player.getInventory().getItemInHand().setAmount(item.getAmount()-1);
            }else{
            player.setItemInHand(new ItemStack(Material.AIR));
            }
            String message = null;
            String displayName = item.getItemMeta().getDisplayName();
            String value = null;
       
            if(item.getType().equals(head.getType()) && displayName != null){
                displayName = displayName.replaceAll(".*\\$", "");
                for(int i = 0; i < displayName.length() - 1; i++){
                    value += displayName.charAt(i);
                }
            double bounty = Double.parseDouble(value);
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco give " + player.getName() + " " + bounty);
            message = ChatColor.GREEN + "Successfully Redeemed Head for $" + value;
            }else{
                message = ChatColor.RED + "That is not a player head!";
            }
            return message;
        }
    }
    
    
     
    Last edited: Dec 15, 2014
Thread Status:
Not open for further replies.

Share This Page