2025-01-29 13:20:04 -05:00
|
|
|
package kamkeel.npcs.controllers.data;
|
2025-01-23 16:10:01 -05:00
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2025-02-20 21:39:02 -05:00
|
|
|
import noppes.npcs.NoppesUtilServer;
|
|
|
|
|
import noppes.npcs.api.entity.IPlayer;
|
2025-02-21 17:30:57 -05:00
|
|
|
import noppes.npcs.api.handler.data.IProfile;
|
|
|
|
|
import noppes.npcs.api.handler.data.ISlot;
|
2025-01-23 16:10:01 -05:00
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2025-02-20 21:39:02 -05:00
|
|
|
import java.util.Map;
|
2025-01-23 16:10:01 -05:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
2025-02-20 21:39:02 -05:00
|
|
|
public class Profile implements IProfile {
|
2025-01-23 16:10:01 -05:00
|
|
|
public EntityPlayer player;
|
2025-02-20 21:39:02 -05:00
|
|
|
public int currentSlotId;
|
|
|
|
|
private Map<Integer, ISlot> slots = new HashMap<>();
|
|
|
|
|
private boolean locked = false;
|
2025-01-23 16:10:01 -05:00
|
|
|
|
2025-02-18 22:22:40 -05:00
|
|
|
public Profile(EntityPlayer player, NBTTagCompound compound) {
|
2025-01-23 16:10:01 -05:00
|
|
|
this.player = player;
|
2025-02-20 21:39:02 -05:00
|
|
|
if(compound.hasKey("CurrentSlotId")){
|
|
|
|
|
this.currentSlotId = compound.getInteger("CurrentSlotId");
|
2025-01-23 16:10:01 -05:00
|
|
|
} else {
|
2025-02-20 21:39:02 -05:00
|
|
|
this.currentSlotId = 0;
|
2025-01-23 16:10:01 -05:00
|
|
|
}
|
|
|
|
|
|
2025-02-20 21:39:02 -05:00
|
|
|
if(compound.hasKey("Slots")){
|
2025-01-23 16:10:01 -05:00
|
|
|
NBTTagCompound slotsCompound = compound.getCompoundTag("Slots");
|
2025-02-20 21:39:02 -05:00
|
|
|
Set<String> keys = slotsCompound.func_150296_c();
|
|
|
|
|
for(String key : keys) {
|
|
|
|
|
try {
|
|
|
|
|
int slotId = Integer.parseInt(key);
|
|
|
|
|
NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key);
|
|
|
|
|
ISlot slot = Slot.fromNBT(slotId, slotNBT);
|
|
|
|
|
slots.put(slotId, slot);
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
// Skip keys that are not valid slot IDs.
|
|
|
|
|
}
|
2025-01-23 16:10:01 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-20 21:39:02 -05:00
|
|
|
public Profile(EntityPlayer player) {
|
|
|
|
|
this.player = player;
|
|
|
|
|
this.currentSlotId = 0;
|
|
|
|
|
// Create a default slot.
|
|
|
|
|
Slot defaultSlot = new Slot(0, "Default Slot");
|
|
|
|
|
defaultSlot.setLastLoaded(System.currentTimeMillis());
|
|
|
|
|
slots.put(0, defaultSlot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public IPlayer getPlayer() {
|
|
|
|
|
return NoppesUtilServer.getIPlayer(player);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getCurrentSlotId() {
|
|
|
|
|
return currentSlotId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<Integer, ISlot> getSlots() {
|
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isLocked() {
|
|
|
|
|
return locked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLocked(boolean locked) {
|
|
|
|
|
this.locked = locked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-01-23 16:10:01 -05:00
|
|
|
public NBTTagCompound writeToNBT() {
|
2025-02-20 21:39:02 -05:00
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
if(player != null)
|
|
|
|
|
compound.setString("Name", player.getCommandSenderName());
|
|
|
|
|
compound.setInteger("CurrentSlotId", currentSlotId);
|
|
|
|
|
NBTTagCompound slotsCompound = new NBTTagCompound();
|
|
|
|
|
for(Map.Entry<Integer, ISlot> entry : slots.entrySet()) {
|
|
|
|
|
// Save only non-temporary slots.
|
|
|
|
|
if(entry.getValue().isTemporary())
|
|
|
|
|
continue;
|
|
|
|
|
slotsCompound.setTag(String.valueOf(entry.getKey()), entry.getValue().toNBT());
|
2025-01-23 16:10:01 -05:00
|
|
|
}
|
2025-02-20 21:39:02 -05:00
|
|
|
compound.setTag("Slots", slotsCompound);
|
|
|
|
|
return compound;
|
2025-01-23 16:10:01 -05:00
|
|
|
}
|
|
|
|
|
}
|