PlayerDeathEvent HELP!!

Discussion in 'Plugin Development' started by Irantwomiles, Mar 5, 2015.

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

    Irantwomiles

    Ok so Im trying to make it so if the player dies it gives the killer a Crate. I've been at this for like hours and in my eyes it looks correct but I think its best if someone else looks at it too! this is all the code I have so far, please if you find any errors post a comment!
    Code:
    package me.iran.bukkit;
    
    import java.util.ArrayList;
    
    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.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class LootCrate extends JavaPlugin implements Listener  {
    
        ArrayList<String> crateyes = new ArrayList<String>();
        ArrayList<String> crateno = new ArrayList<String>();
    
        private Inventory inv;
        private ItemStack items;
       
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            if (this.crateyes.contains(player.getName())) {
                player.sendMessage(ChatColor.AQUA + "You have a crate Awaiting!");
            } else {
                this.crateno.add(player.getName());
            }
        }
       
        public Inventory crate() {
            //Creates and Inventory
            this.inv = Bukkit.getServer().createInventory(null, 18, ChatColor.GREEN + "Irantwomiles");
           
            ItemStack diamond = new ItemStack(Material.DIAMOND, 64);
            this.items = new ItemStack(diamond);
           
            //setting items into the inventory
            this.inv.setItem(10, this.items);
           
            return this.inv;
        }
       
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("pleaseworkgive")) {
                if(args.length == 0) {
                    player.sendMessage("Please specify a player");
                    return true;
                }
               
                Player target = Bukkit.getServer().getPlayer(args[0]);
                this.crateno.remove(target.getName());
                this.crateyes.add(target.getName());
                target.sendMessage("You recieved a crate from " + sender.getName());
                return true;
            }
           
            if(cmd.getName().equalsIgnoreCase("pleaseworkopen")) {
                if(this.crateyes.contains(player.getName())) {
                    this.crateyes.remove(player.getName());
                    this.crateno.add(player.getName());
                    player.openInventory(crate());
                    player.sendMessage("opened!");
                }
                if(this.crateno.contains(player.getName())){
                    player.sendMessage("you dont have a crate!");
                }
            }
            return true;
        }
       
        @EventHandler
       
        public void onDeathCrate(PlayerDeathEvent event) {
            Player killer = event.getEntity().getKiller();
            Player dead = event.getEntity();
           
            if(killer instanceof Player && dead instanceof Player) {
                Player player = (Player) killer;
                if(this.crateno.contains(player.getName())) {
                    this.crateno.remove(player.getName());
                    this.crateyes.add(player.getName());
                    player.sendMessage("You recieved a crate from killing " + dead);
                }
            }
           
           
        }
    }
    
     
  2. Offline

    Skionz

  3. Offline

    Irantwomiles

    @Skionz If that works I will kiss you, marry you, have your kids

    @Skionz I fucking love you so much right now, you have no clue! Btw it worked

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
    Skionz likes this.
  4. Offline

    SuperOriginal

    When's the marriage?
     
    deleted_90940145, Konato_K and Skionz like this.
  5. Offline

    Irantwomiles

    Actually I got another problems, For some reason this only works sometimes? like when I relog it sometimes works. Idk whats wrong

    is anyone willing to take a look at the plugin to see whats wrong with it? it sometimes works and it sometimes doesnt, its weird

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

    BaconStripzMan

    Post the updated code
     
  7. Offline

    Irantwomiles

    @BaconStripzMan will do but I'm at school right now, also I don't think I changed it much from the one I posted
     
Thread Status:
Not open for further replies.

Share This Page