- Contributors:
- RealEmpire
Save
Basic plugin which can be used in FFA servers.
Commands:
/save | Saves your Inventory till you logout
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);
}
}
-
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]