mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 08:38:31 +00:00
Better Reorganization
This commit is contained in:
1 parent
a328a635d7
commit
da0489296e
38 files changed
+151
-144
No files matched your search
@@ -0,0 +1,92 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.IProfile;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Profile implements IProfile {
|
||||
public EntityPlayer player;
|
||||
public int currentSlotId;
|
||||
private Map<Integer, ISlot> slots = new HashMap<>();
|
||||
private boolean locked = false;
|
||||
|
||||
public Profile(EntityPlayer player, NBTTagCompound compound) {
|
||||
this.player = player;
|
||||
if(compound.hasKey("CurrentSlotId")){
|
||||
this.currentSlotId = compound.getInteger("CurrentSlotId");
|
||||
} else {
|
||||
this.currentSlotId = 0;
|
||||
}
|
||||
|
||||
if(compound.hasKey("Slots")){
|
||||
NBTTagCompound slotsCompound = compound.getCompoundTag("Slots");
|
||||
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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
public NBTTagCompound writeToNBT() {
|
||||
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());
|
||||
}
|
||||
compound.setTag("Slots", slotsCompound);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user