mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
kinda ugly but it works
inventory saving: complete
This commit is contained in:
parent
f758be9e70
commit
135d1af27d
@ -0,0 +1,55 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigInventory;
|
||||
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "View player inventory information of players.", usage = "/<command> <player> <slot>", aliases = "inv")
|
||||
public class Command_inventory extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
VPlayer vPlayer = plugin.pv.getVerificationPlayer(args[0]);
|
||||
if (vPlayer == null)
|
||||
{
|
||||
msg("Could not find player or find that player's data.");
|
||||
return true;
|
||||
}
|
||||
ConfigInventory inv = vPlayer.getInventory();
|
||||
int slot;
|
||||
try
|
||||
{
|
||||
slot = Integer.valueOf(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
msg("That is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
ItemStack stack = inv.get(slot);
|
||||
if (stack == null)
|
||||
{
|
||||
stack = new ItemStack(Material.AIR, 1);
|
||||
}
|
||||
msg(args[0] + "'s Inventory - Slot " + slot + ":");
|
||||
msg(" - Material: " + stack.getType().name());
|
||||
msg(" - Amount: " + stack.getAmount());
|
||||
if (inv.hasNBT(slot))
|
||||
{
|
||||
msg(" - NBT Data: " + inv.getNBT(slot));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package me.totalfreedom.totalfreedommod.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ConfigInventory
|
||||
{
|
||||
@Getter
|
||||
@Setter
|
||||
private Map<Integer, ItemStack> inventoryItems;
|
||||
|
||||
public ConfigInventory(Inventory inv)
|
||||
{
|
||||
updateInventory(inv);
|
||||
}
|
||||
|
||||
public void set(int location, ItemStack stack)
|
||||
{
|
||||
inventoryItems.put(location, stack);
|
||||
}
|
||||
|
||||
public ItemStack get(int location)
|
||||
{
|
||||
return inventoryItems.get(location);
|
||||
}
|
||||
|
||||
public boolean hasNBT(int location)
|
||||
{
|
||||
return CraftItemStack.asNMSCopy(inventoryItems.get(location)).hasTag();
|
||||
}
|
||||
|
||||
public String getNBT(int location)
|
||||
{
|
||||
return CraftItemStack.asNMSCopy(inventoryItems.get(location)).getTag().toString();
|
||||
}
|
||||
|
||||
public void updateInventory(Inventory inv)
|
||||
{
|
||||
inventoryItems = new HashMap<>();
|
||||
for (int i = 0; i < inv.getSize(); i++)
|
||||
{
|
||||
inventoryItems.put(i, inv.getItem(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void save(ConfigurationSection cs)
|
||||
{
|
||||
for (int i = 0; i < inventoryItems.size(); i++)
|
||||
{
|
||||
ItemStack currentStack = inventoryItems.get(i);
|
||||
net.minecraft.server.v1_14_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(currentStack);
|
||||
if (currentStack == null)
|
||||
{
|
||||
ItemStack air = new ItemStack(Material.AIR, 1);
|
||||
inventoryItems.put(i, air);
|
||||
currentStack = air;
|
||||
}
|
||||
cs.set("inventory." + i + ".type", currentStack.getType().name());
|
||||
cs.set("inventory." + i + ".amount", currentStack.getAmount());
|
||||
if (nmsStack.hasTag())
|
||||
{
|
||||
cs.set("inventory." + i + ".nbt", nmsStack.getTag().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -180,7 +180,9 @@ public class PlayerList extends FreedomService
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
final String ip = Ips.getIp(event.getPlayer());
|
||||
plugin.pv.save();
|
||||
final Player player = event.getPlayer();
|
||||
final String ip = Ips.getIp(player);
|
||||
playerMap.remove(ip);
|
||||
dataMap.remove(ip);
|
||||
}
|
||||
|
@ -5,10 +5,12 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigInventory;
|
||||
import net.pravian.aero.base.ConfigLoadable;
|
||||
import net.pravian.aero.base.ConfigSavable;
|
||||
import net.pravian.aero.base.Validatable;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -37,6 +39,9 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean rideToggle = true;
|
||||
@Getter
|
||||
@Setter
|
||||
private ConfigInventory inventory = null;
|
||||
|
||||
public VPlayer(String name)
|
||||
{
|
||||
@ -59,6 +64,7 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
|
||||
tag = cs.getString("tag", null);
|
||||
clearChatOptOut = cs.getBoolean("clearChatOptOut", false);
|
||||
rideToggle = cs.getBoolean("rideToggle", true);
|
||||
inventory = new ConfigInventory(Bukkit.getPlayer(name).getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,6 +78,8 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
|
||||
cs.set("ips", Lists.newArrayList(ips));
|
||||
cs.set("clearChatOptOut", clearChatOptOut);
|
||||
cs.set("rideToggle", rideToggle);
|
||||
inventory.updateInventory(Bukkit.getPlayer(name).getInventory());
|
||||
inventory.save(cs);
|
||||
}
|
||||
|
||||
public List<String> getIps()
|
||||
|
Loading…
Reference in New Issue
Block a user