2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.controllers;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
2022-01-12 22:59:03 -06:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2022-01-12 22:59:03 -06:00
|
|
|
import noppes.npcs.EventHooks;
|
2022-05-11 22:08:31 -05:00
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
2022-01-12 22:59:03 -06:00
|
|
|
import noppes.npcs.scripted.event.FactionEvent;
|
2022-05-11 22:08:31 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public class PlayerFactionData {
|
|
|
|
|
public HashMap<Integer,Integer> factionData = new HashMap<Integer,Integer>();
|
|
|
|
|
|
|
|
|
|
public void loadNBTData(NBTTagCompound compound) {
|
|
|
|
|
HashMap<Integer,Integer> factionData = new HashMap<Integer,Integer>();
|
|
|
|
|
if(compound == null)
|
|
|
|
|
return;
|
|
|
|
|
NBTTagList list = compound.getTagList("FactionData", 10);
|
|
|
|
|
if(list == null){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < list.tagCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
|
|
|
|
|
factionData.put(nbttagcompound.getInteger("Faction"),nbttagcompound.getInteger("Points"));
|
|
|
|
|
}
|
|
|
|
|
this.factionData = factionData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void saveNBTData(NBTTagCompound compound) {
|
|
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
for(int faction : factionData.keySet()){
|
|
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
|
|
|
nbttagcompound.setInteger("Faction", faction);
|
|
|
|
|
nbttagcompound.setInteger("Points", factionData.get(faction));
|
|
|
|
|
list.appendTag(nbttagcompound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
compound.setTag("FactionData", list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getFactionPoints(int id) {
|
|
|
|
|
if(!factionData.containsKey(id)){
|
2022-01-10 15:21:48 -06:00
|
|
|
Faction faction = FactionController.getInstance().get(id);
|
2018-09-13 12:03:28 -04:00
|
|
|
factionData.put(id, faction == null? -1 : faction.defaultPoints);
|
|
|
|
|
}
|
|
|
|
|
return factionData.get(id);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 22:59:03 -06:00
|
|
|
public void increasePoints(int factionId, int points, EntityPlayer player) {
|
2022-05-11 22:08:31 -05:00
|
|
|
EventHooks.onFactionPoints(new FactionEvent.FactionPoints((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayerMP) player), FactionController.getInstance().get(factionId), points < 0, points));
|
2018-09-13 12:03:28 -04:00
|
|
|
if(!factionData.containsKey(factionId)){
|
2022-01-10 15:21:48 -06:00
|
|
|
Faction faction = FactionController.getInstance().get(factionId);
|
2018-09-13 12:03:28 -04:00
|
|
|
factionData.put(factionId, faction == null? -1 : faction.defaultPoints);
|
|
|
|
|
}
|
|
|
|
|
factionData.put(factionId, factionData.get(factionId) + points);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound getPlayerGuiData(){
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
saveNBTData(compound);
|
|
|
|
|
|
|
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
for(int id : factionData.keySet()){
|
2022-01-10 15:21:48 -06:00
|
|
|
Faction faction = FactionController.getInstance().get(id);
|
2018-09-13 12:03:28 -04:00
|
|
|
if(faction == null || faction.hideFaction)
|
|
|
|
|
continue;
|
|
|
|
|
NBTTagCompound com = new NBTTagCompound();
|
|
|
|
|
faction.writeNBT(com);
|
|
|
|
|
list.appendTag(com);
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("FactionList", list);
|
|
|
|
|
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|