Item On Death

This plugin is currently not working properly, and is not recommended for use. I will release an update as soon as I can to fix the major issue I did not see when I was writing the plugin.

The ItemOnDeath plugin is pretty self explanatory; when a player dies, one (random) item is kept from their inventory and is returned to them when they respawn. There is no configuration for this plugin (yet).

Developed by: Derragon (Scott Stevens) Owned by: Open Source Programming Group Source Code: Open

Features:

  • Keep one (random) item on death.

Notes

  • I am accepting ideas for other server plugins and features for this plugin/other plugin(s).
  • This plugin is tested for major bugs/issues, and updates are not released unless those bugs/issues are fixed.
  • All of my code is open-source, and is meant to help other plugin developers learn.
  • This plugin was designed by the OpenSourceProgramming group, which consists of only myself (Derragon) currently.
  • If you would like to join the OpenSourceProgramming group, please send me a PM with your previous programming experience, along with 1 (one) or more references that can vouch for your previous experience.

To-Do:

  • Create configuration abilities.
  • Add new feature(s).

Source Code:

package ca.bcminecraft.itemondeath;

import java.util.HashMap;
import java.util.Random;
import java.util.logging.Logger;
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.PlayerRespawnEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

/**
 *
 * @author Scott
 */
public class Main extends JavaPlugin implements Listener {
    
    Logger log = Logger.getLogger("Minecraft");
    Random r = new Random();
    HashMap<String, ItemStack> returnItems = new HashMap();
    
    public void onEnable () {
        log.info("Enabled.");
        getServer().getPluginManager().registerEvents(this, this);
    }
    
    public void onDisable () {
        log.info("Disabled.");
    }
    
    @EventHandler
    public boolean onPlayerDeath(PlayerDeathEvent e){
        Player p = e.getEntity();
        Inventory i = p.getInventory();
        int toGet = r.nextInt(i.getContents().length - 1);
        ItemStack item = i.getItem(toGet);
        
        returnItems.put(p.getName(), item);
        if (returnItems.containsKey(p.getName())){
            return true;
        } else {
            return false;
        }
    }
    
    @EventHandler
    public boolean onPlayerRespawn(PlayerRespawnEvent e){
        Player p = e.getPlayer();
        String name = p.getName();
        if (returnItems.containsKey(name)){
            p.setItemInHand(returnItems.get(name));
            if (p.getItemInHand() == returnItems.get(name)){
                returnItems.remove(name);
            }
            else {
                return false;
            }
        }
        return true;
    }
    
}

You must login to post a comment. Don't have an account? Register to get one!

  • 1 comment
  • Avatar of tommycake50 tommycake50 Jun 03, 2013 at 18:46 UTC - 0 likes

    I guess this is discontinued then, Shame, i think ill compile this and edit it slightly for the server i am admin on this looks like a nice plugin(if a little outdated).

    Last edited Jun 03, 2013 by tommycake50
  • 1 comment

Facts

Date created
Jul 15, 2012
Categories
Last update
Jul 15, 2012
Development stage
Alpha
License
GNU General Public License version 3 (GPLv3)
Downloads
2

Authors