1. We are planning scheduled maintenance on this website on Friday 5 March (tomorrow) at 4:00 am UTC. It is estimated that this maintenance will last 15 minutes. You can view this time in your local timezone here. Thanks.
    Dismiss Notice

Save Inventory 2016-01-16

/save [Saves hotbar until you logout]

  1. RealEmpire
    Contributors:
    RealEmpire
    Save

    Basic plugin which can be used in FFA servers.

    Commands:
    /save | Saves your Inventory till you logout
    [​IMG]

    Thats about it. Enjoy I guess

    Source Code:
    Code (Text):
    package me.Kruciial.save;

    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.UUID;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    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.PlayerQuitEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main
      extends JavaPlugin
      implements Listener, CommandExecutor
    {
      public Map<UUID, ItemStack[]> inventories = new HashMap();
      public Map<UUID, ItemStack[]> armor = new HashMap();
     
      public void onEnable()
      {
        Bukkit.getPluginManager().registerEvents(this, this);
      }
     
      public void onDisable() {}
     
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
      {
        if (!(sender instanceof Player))
        {
          sender.sendMessage("You have to be a player to perform this command!");
          return false;
        }
        Player p = (Player)sender;
        if (label.equalsIgnoreCase("save"))
        {
          this.inventories.put(p.getUniqueId(), p.getInventory().getContents());
          this.armor.put(p.getUniqueId(), p.getInventory().getArmorContents());
          msg(p, new String[] { "&7? &6FFA &7? &6Your inventory has been saved until you logout!" });
        }
        return false;
      }
     
      @EventHandler
      public void onQuit(PlayerQuitEvent e)
      {
        Player p = e.getPlayer();
        if (this.inventories.containsKey(p.getUniqueId())) {
          this.inventories.remove(p.getUniqueId());
        }
        if (this.armor.containsKey(p.getUniqueId())) {
          this.armor.remove(p.getUniqueId());
        }
      }
     
      @EventHandler
      public void onDeath(PlayerDeathEvent e)
      {
        Player p = e.getEntity();
        if ((this.inventories.containsKey(p.getUniqueId())) || (this.armor.containsKey(p.getUniqueId()))) {
          e.getDrops().clear();
        }
      }
     
      @EventHandler
      public void onRespawn(PlayerRespawnEvent e)
      {
        Player p = e.getPlayer();
        if (this.inventories.containsKey(e.getPlayer().getUniqueId())) {
          p.getInventory().setContents((ItemStack[])this.inventories.get(p.getUniqueId()));
        }
        if (this.armor.containsKey(p.getUniqueId())) {
          p.getInventory().setArmorContents((ItemStack[])this.armor.get(p.getUniqueId()));
        }
      }
     
      public void msg(Player p, String... msg)
      {
        String[] arrayOfString;
        int j = (arrayOfString = msg).length;
        for (int i = 0; i < j; i++)
        {
          String s = arrayOfString[i];
          p.sendMessage(color(s));
        }
      }
     
      public boolean isInt(String s)
      {
        try
        {
          Integer.parseInt(s);
          return true;
        }
        catch (Exception localException) {}
        return false;
      }
     
      public String color(String s)
      {
        return ChatColor.translateAlternateColorCodes('&', s);
      }
    }
     

    gryphus71 likes this.

Recent Updates

  1. Layout updated

Recent Reviews

  1. aliraqial7lo
    aliraqial7lo
    5/5,
    Version: 2016-01-16
    very very good .well done <3
    ........................................................
  2. SquidCraftBBB
    SquidCraftBBB
    5/5,
    Version: 2016-01-16
    100 .................................................................................................................
  3. Betob89
    Betob89
    5/5,
    Version: 2016-01-16
    Good work cant you add to traduce de message to spanish and permission to ejecute the comand save thanks
  4. iTzGhostx
    iTzGhostx
    5/5,
    Version: 2016-01-16
    Hi there is an error in the deathevents wen i die the items respawn but the arrmor not respawning please fix it
  5. Golicraft
    Golicraft
    5/5,
    Version: 2016-01-16
    Its me again
    Love it :D

    Can you please add when you have killed someone you must died and then write /save

    because i have ffa rewards on killstreak
    so they can stack up and then /Save

    Thanks
    1. RealEmpire
      Author's Response
      Well, you could get them to type /save when they get rewards or get a KillCommand plugin.