mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 21:20:04 +00:00
API Changes:
-Implemented interfaces for all jobs & roles. ScriptPlayer: -Added getData() function, which returns player data objects. IPlayerData: New class that holds all player data for modification. -Holds dialog, bank, quest, transport, faction, item giver, and mail data. -Also holds companion data, with functions has/set/getCompanion, and a getCompanionID function to differentiate companions.
This commit is contained in:
1 parent
587f63396f
commit
63a1525ee2
66 files changed
+1418
-207
No files matched your search
@@ -5,11 +5,15 @@ import java.util.HashMap;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.BankController;
|
||||
import noppes.npcs.scripted.interfaces.handler.IPlayerBankData;
|
||||
|
||||
public class PlayerBankData{
|
||||
public class PlayerBankData implements IPlayerBankData {
|
||||
private final PlayerData parent;
|
||||
public HashMap<Integer,BankData> banks;
|
||||
public PlayerBankData(){
|
||||
|
||||
public PlayerBankData(PlayerData parent){
|
||||
banks = new HashMap<Integer,BankData>();
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void loadNBTData(NBTTagCompound compound) {
|
||||
|
||||
@@ -15,19 +15,23 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.entity.data.DataSkinOverlays;
|
||||
import noppes.npcs.entity.data.DataTimers;
|
||||
import noppes.npcs.roles.RoleCompanion;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.interfaces.entity.ICustomNpc;
|
||||
import noppes.npcs.scripted.interfaces.handler.*;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
public class PlayerData implements IExtendedEntityProperties{
|
||||
public PlayerDialogData dialogData = new PlayerDialogData();
|
||||
public PlayerBankData bankData = new PlayerBankData();
|
||||
public PlayerQuestData questData = new PlayerQuestData();
|
||||
public PlayerTransportData transportData = new PlayerTransportData();
|
||||
public PlayerFactionData factionData = new PlayerFactionData();
|
||||
public PlayerItemGiverData itemgiverData = new PlayerItemGiverData();
|
||||
public PlayerMailData mailData = new PlayerMailData();
|
||||
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerDialogData dialogData = new PlayerDialogData(this);
|
||||
public PlayerBankData bankData = new PlayerBankData(this);
|
||||
public PlayerQuestData questData = new PlayerQuestData(this);
|
||||
public PlayerTransportData transportData = new PlayerTransportData(this);
|
||||
public PlayerFactionData factionData = new PlayerFactionData(this);
|
||||
public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this);
|
||||
public PlayerMailData mailData = new PlayerMailData(this);
|
||||
|
||||
public DataTimers timers = new DataTimers(this);
|
||||
public DataSkinOverlays skinOverlays = new DataSkinOverlays(this);
|
||||
|
||||
@@ -245,4 +249,48 @@ public class PlayerData implements IExtendedEntityProperties{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCompanion(ICustomNpc npc) {
|
||||
this.setCompanion((EntityNPCInterface) npc.getMCEntity());
|
||||
}
|
||||
|
||||
public ICustomNpc getCompanion() {
|
||||
return (ICustomNpc) NpcAPI.Instance().getIEntity(activeCompanion);
|
||||
}
|
||||
|
||||
public int getCompanionID() {
|
||||
return companionID;
|
||||
}
|
||||
|
||||
public IPlayerDialogData getDialogData() {
|
||||
return dialogData;
|
||||
}
|
||||
|
||||
public IPlayerBankData getBankData() {
|
||||
return bankData;
|
||||
}
|
||||
|
||||
public IPlayerQuestData getQuestData() {
|
||||
return questData;
|
||||
}
|
||||
|
||||
public IPlayerTransportData getTransportData() {
|
||||
return transportData;
|
||||
}
|
||||
|
||||
public IPlayerFactionData getFactionData() {
|
||||
return factionData;
|
||||
}
|
||||
|
||||
public IPlayerItemGiverData getItemGiverData() {
|
||||
return itemgiverData;
|
||||
}
|
||||
|
||||
public IPlayerMailData getMailData() {
|
||||
return mailData;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
PlayerDataController.instance.savePlayerData(this);
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,15 @@ import java.util.HashSet;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.scripted.interfaces.handler.IPlayerDialogData;
|
||||
|
||||
public class PlayerDialogData{
|
||||
public class PlayerDialogData implements IPlayerDialogData {
|
||||
private final PlayerData parent;
|
||||
public HashSet<Integer> dialogsRead = new HashSet<Integer>();
|
||||
|
||||
public PlayerDialogData(PlayerData parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void loadNBTData(NBTTagCompound compound) {
|
||||
HashSet<Integer> dialogsRead = new HashSet<Integer>();
|
||||
@@ -35,5 +41,16 @@ public class PlayerDialogData{
|
||||
|
||||
compound.setTag("DialogData", list);
|
||||
}
|
||||
|
||||
|
||||
public boolean hasReadDialog(int id) {
|
||||
return dialogsRead.contains(id);
|
||||
}
|
||||
|
||||
public void readDialog(int id) {
|
||||
dialogsRead.add(id);
|
||||
}
|
||||
|
||||
public void unreadDialog(int id) {
|
||||
dialogsRead.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,20 @@ import noppes.npcs.controllers.FactionController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.FactionEvent;
|
||||
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
||||
import noppes.npcs.scripted.interfaces.handler.IPlayerFactionData;
|
||||
|
||||
public class PlayerFactionData {
|
||||
public class PlayerFactionData implements IPlayerFactionData {
|
||||
private final PlayerData parent;
|
||||
public HashMap<Integer,Integer> factionData = new HashMap<Integer,Integer>();
|
||||
|
||||
|
||||
public PlayerFactionData() {
|
||||
parent = null;
|
||||
}
|
||||
|
||||
public PlayerFactionData(PlayerData parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void loadNBTData(NBTTagCompound compound) {
|
||||
HashMap<Integer,Integer> factionData = new HashMap<Integer,Integer>();
|
||||
if(compound == null)
|
||||
@@ -79,4 +89,19 @@ public class PlayerFactionData {
|
||||
return compound;
|
||||
}
|
||||
|
||||
public int getPoints(int id) {
|
||||
return this.getFactionPoints(id);
|
||||
}
|
||||
|
||||
public void addPoints(int id, int points) {
|
||||
if (parent != null) {
|
||||
this.increasePoints(id, points, parent.player);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPoints(int id, int points) {
|
||||
if (parent != null) {
|
||||
increasePoints(id, points-getFactionPoints(id), parent.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,25 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.controllers.GlobalDataController;
|
||||
import noppes.npcs.roles.JobItemGiver;
|
||||
import noppes.npcs.scripted.interfaces.handler.IPlayerItemGiverData;
|
||||
import noppes.npcs.scripted.interfaces.jobs.IJobItemGiver;
|
||||
import noppes.npcs.scripted.roles.ScriptJobItemGiver;
|
||||
|
||||
public class PlayerItemGiverData{
|
||||
public class PlayerItemGiverData implements IPlayerItemGiverData {
|
||||
private final PlayerData parent;
|
||||
private HashMap<Integer, Long> itemgivers = new HashMap<Integer,Long>();
|
||||
private HashMap<Integer, Integer> chained = new HashMap<Integer,Integer>();
|
||||
|
||||
|
||||
public PlayerItemGiverData(PlayerData parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void loadNBTData(NBTTagCompound compound) {
|
||||
chained = NBTTags.getIntegerIntegerMap(compound.getTagList("ItemGiverChained", 10));
|
||||
itemgivers = NBTTags.getIntegerLongMap(compound.getTagList("ItemGiversList", 10));
|
||||
@@ -37,4 +47,29 @@ public class PlayerItemGiverData{
|
||||
public void setItemIndex(JobItemGiver jobItemGiver, int i) {
|
||||
chained.put(jobItemGiver.itemGiverId, i);
|
||||
}
|
||||
|
||||
public long getTime(IJobItemGiver jobItemGiver){
|
||||
return itemgivers.get(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId);
|
||||
}
|
||||
|
||||
public void setTime(IJobItemGiver jobItemGiver, long day) {
|
||||
itemgivers.put(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId, day);
|
||||
}
|
||||
|
||||
public boolean hasInteractedBefore(IJobItemGiver jobItemGiver) {
|
||||
return itemgivers.containsKey(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId);
|
||||
}
|
||||
|
||||
public IJobItemGiver[] getItemGivers() {
|
||||
ArrayList<IJobItemGiver> list = new ArrayList<>();
|
||||
for (JobItemGiver jobItemGiver : GlobalDataController.instance.itemGivers.values()) {
|
||||
if (jobItemGiver.npc != null) {
|
||||
list.add(new ScriptJobItemGiver(jobItemGiver.npc));
|
||||
} else {
|
||||
list.add(new ScriptJobItemGiver(jobItemGiver));
|
||||
}
|
||||
}
|
||||
|
||||
return list.toArray(new IJobItemGiver[0]);
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,17 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.IPlayerMail;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.IQuest;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
|
||||
public class PlayerMail implements IInventory{
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PlayerMail implements IInventory, IPlayerMail {
|
||||
public String subject = "";
|
||||
public String sender = "";
|
||||
public NBTTagCompound message = new NBTTagCompound();
|
||||
@@ -202,4 +209,99 @@ public class PlayerMail implements IInventory{
|
||||
mail.readNBT(writeNBT());
|
||||
return mail;
|
||||
}
|
||||
|
||||
public void setPageText(String[] pages) {
|
||||
NBTTagList bookPages = new NBTTagList();
|
||||
for (String text : pages) {
|
||||
bookPages.appendTag(new NBTTagString(text));
|
||||
}
|
||||
|
||||
message.setTag("pages", bookPages);
|
||||
}
|
||||
|
||||
public String[] getPageText() {
|
||||
NBTTagList bookPages = new NBTTagList();
|
||||
|
||||
if(message.hasKey("pages"))
|
||||
bookPages = message.getTagList("pages", 8);
|
||||
|
||||
if (bookPages != null)
|
||||
{
|
||||
bookPages = (NBTTagList)bookPages.copy();
|
||||
ArrayList<String> pageStrings = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < bookPages.tagCount(); i++) {
|
||||
pageStrings.add(bookPages.getStringTagAt(i));
|
||||
}
|
||||
|
||||
return pageStrings.toArray(new String[0]);
|
||||
} else {
|
||||
return new String[]{""};
|
||||
}
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
NBTTagList bookPages = new NBTTagList();
|
||||
|
||||
if(message.hasKey("pages"))
|
||||
bookPages = message.getTagList("pages", 8);
|
||||
|
||||
int bookTotalPages = 0;
|
||||
if (bookPages != null)
|
||||
{
|
||||
bookPages = (NBTTagList)bookPages.copy();
|
||||
bookTotalPages = bookPages.tagCount();
|
||||
|
||||
if (bookTotalPages < 1)
|
||||
{
|
||||
bookTotalPages = 1;
|
||||
}
|
||||
|
||||
return bookTotalPages;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setSender(String sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public String getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public long getTimePast() {
|
||||
return timePast;
|
||||
}
|
||||
|
||||
public long getTimeSent() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public IItemStack[] getItems() {
|
||||
ArrayList<IItemStack> list = new ArrayList<>();
|
||||
for (ItemStack itemStack : items) {
|
||||
list.add(NpcAPI.Instance().getIItemStack(itemStack));
|
||||
}
|
||||
|
||||
return list.toArray(new IItemStack[0]);
|
||||
}
|
||||
|
||||
public void setItems(IItemStack[] items) {
|
||||
ArrayList<ItemStack> list = new ArrayList<>();
|
||||
for (IItemStack itemStack : items) {
|
||||
list.add(itemStack.getMCItemStack());
|
||||
}
|
||||
|
||||
this.items = list.toArray(new ItemStack[0]);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,21 @@ import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.scripted.interfaces.handler.IPlayerMailData;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.IPlayerMail;
|
||||
|
||||
public class PlayerMailData{
|
||||
public class PlayerMailData implements IPlayerMailData {
|
||||
private final PlayerData parent;
|
||||
public ArrayList<PlayerMail> playermail = new ArrayList<PlayerMail>();
|
||||
|
||||
public PlayerMailData() {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
public PlayerMailData(PlayerData parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void loadNBTData(NBTTagCompound compound) {
|
||||
ArrayList<PlayerMail> newmail = new ArrayList<PlayerMail>();
|
||||
NBTTagList list = compound.getTagList("MailData", 10);
|
||||
@@ -39,4 +50,56 @@ public class PlayerMailData{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addMail(IPlayerMail mail) {
|
||||
playermail.add((PlayerMail) mail);
|
||||
}
|
||||
|
||||
public void removeMail(IPlayerMail mail) {
|
||||
playermail.remove((PlayerMail) mail);
|
||||
}
|
||||
|
||||
public boolean hasMail(IPlayerMail mail) {
|
||||
return playermail.contains((PlayerMail) mail);
|
||||
}
|
||||
|
||||
public IPlayerMail[] getAllMail() {
|
||||
return playermail.toArray(new IPlayerMail[0]);
|
||||
}
|
||||
|
||||
public IPlayerMail[] getUnreadMail() {
|
||||
ArrayList<IPlayerMail> mails = new ArrayList<>();
|
||||
|
||||
for (PlayerMail mail : playermail) {
|
||||
if (!mail.beenRead) {
|
||||
mails.add(mail);
|
||||
}
|
||||
}
|
||||
|
||||
return mails.toArray(new IPlayerMail[0]);
|
||||
}
|
||||
|
||||
public IPlayerMail[] getReadMail() {
|
||||
ArrayList<IPlayerMail> mails = new ArrayList<>();
|
||||
|
||||
for (PlayerMail mail : playermail) {
|
||||
if (mail.beenRead) {
|
||||
mails.add(mail);
|
||||
}
|
||||
}
|
||||
|
||||
return mails.toArray(new IPlayerMail[0]);
|
||||
}
|
||||
|
||||
public IPlayerMail[] getMailFrom(String sender) {
|
||||
ArrayList<IPlayerMail> mails = new ArrayList<>();
|
||||
|
||||
for (PlayerMail mail : playermail) {
|
||||
if (mail.sender.equals(sender)) {
|
||||
mails.add(mail);
|
||||
}
|
||||
}
|
||||
|
||||
return mails.toArray(new IPlayerMail[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -16,14 +18,20 @@ import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.quests.QuestInterface;
|
||||
import noppes.npcs.scripted.interfaces.handler.IPlayerQuestData;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.IQuest;
|
||||
|
||||
public class PlayerQuestData {
|
||||
public class PlayerQuestData implements IPlayerQuestData {
|
||||
private final PlayerData parent;
|
||||
public IQuest trackedQuest = null;
|
||||
|
||||
public HashMap<Integer,QuestData> activeQuests = new HashMap<Integer,QuestData>();
|
||||
public HashMap<Integer,Long> finishedQuests = new HashMap<Integer,Long>();
|
||||
|
||||
|
||||
public PlayerQuestData(PlayerData parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void loadNBTData(NBTTagCompound mainCompound) {
|
||||
if(mainCompound == null)
|
||||
return;
|
||||
@@ -129,5 +137,76 @@ public class PlayerQuestData {
|
||||
return bo;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public IQuest getTrackedQuest() {
|
||||
return trackedQuest;
|
||||
}
|
||||
|
||||
public void startQuest(int id) {
|
||||
Quest quest = QuestController.instance.quests.get(id);
|
||||
if (quest == null)
|
||||
return;
|
||||
if(activeQuests.containsKey(id))
|
||||
return;
|
||||
QuestData questdata = new QuestData(quest);
|
||||
activeQuests.put(id, questdata);
|
||||
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
}
|
||||
|
||||
public void finishQuest(int id) {
|
||||
Quest quest = QuestController.instance.quests.get(id);
|
||||
if (quest == null)
|
||||
return;
|
||||
finishedQuests.put(id, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void stopQuest(int id) {
|
||||
Quest quest = QuestController.instance.quests.get(id);
|
||||
if (quest == null)
|
||||
return;
|
||||
activeQuests.remove(id);
|
||||
}
|
||||
|
||||
public void removeQuest(int id) {
|
||||
Quest quest = QuestController.instance.quests.get(id);
|
||||
if (quest == null)
|
||||
return;
|
||||
activeQuests.remove(id);
|
||||
finishedQuests.remove(id);
|
||||
}
|
||||
|
||||
public boolean hasFinishedQuest(int id){
|
||||
return finishedQuests.containsKey(id);
|
||||
}
|
||||
|
||||
public boolean hasActiveQuest(int id){
|
||||
return activeQuests.containsKey(id);
|
||||
}
|
||||
|
||||
public IQuest[] getActiveQuests() {
|
||||
List<IQuest> quests = new ArrayList<>();
|
||||
|
||||
for (int id : activeQuests.keySet()) {
|
||||
IQuest quest = (IQuest) QuestController.instance.quests.get(id);
|
||||
if (quest != null) {
|
||||
quests.add(quest);
|
||||
}
|
||||
}
|
||||
|
||||
return (IQuest[])quests.toArray(new IQuest[0]);
|
||||
}
|
||||
|
||||
public IQuest[] getFinishedQuests() {
|
||||
List<IQuest> quests = new ArrayList<>();
|
||||
|
||||
for (int id : finishedQuests.keySet()) {
|
||||
IQuest quest = (IQuest) QuestController.instance.quests.get(id);
|
||||
if (quest != null) {
|
||||
quests.add(quest);
|
||||
}
|
||||
}
|
||||
|
||||
return (IQuest[])quests.toArray(new IQuest[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,22 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.TransportController;
|
||||
import noppes.npcs.scripted.interfaces.handler.IPlayerTransportData;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation;
|
||||
|
||||
public class PlayerTransportData{
|
||||
public class PlayerTransportData implements IPlayerTransportData {
|
||||
private final PlayerData parent;
|
||||
public HashSet<Integer> transports = new HashSet<Integer>();
|
||||
|
||||
public PlayerTransportData(PlayerData parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void loadNBTData(NBTTagCompound compound) {
|
||||
HashSet<Integer> dialogsRead = new HashSet<Integer>();
|
||||
if(compound == null)
|
||||
@@ -35,5 +44,34 @@ public class PlayerTransportData{
|
||||
|
||||
compound.setTag("TransportData", list);
|
||||
}
|
||||
|
||||
|
||||
public boolean hasTransport(int id) {
|
||||
return transports.contains(id);
|
||||
}
|
||||
|
||||
public void addTransport(int id) {
|
||||
transports.add(id);
|
||||
}
|
||||
|
||||
public void addTransport(ITransportLocation location) {
|
||||
transports.add(location.getId());
|
||||
}
|
||||
|
||||
public ITransportLocation getTransport(int id) {
|
||||
return TransportController.getInstance().getTransport(id);
|
||||
}
|
||||
|
||||
public ITransportLocation[] getTransports() {
|
||||
ArrayList<ITransportLocation> list = new ArrayList<>();
|
||||
for (int id : transports) {
|
||||
ITransportLocation location = TransportController.getInstance().getTransport(id);
|
||||
list.add(location);
|
||||
}
|
||||
|
||||
return list.toArray(new ITransportLocation[0]);
|
||||
}
|
||||
|
||||
public void removeTransport(int id) {
|
||||
transports.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,24 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.TransportController;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.ITransportCategory;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation;
|
||||
|
||||
public class TransportCategory {
|
||||
public class TransportCategory implements ITransportCategory {
|
||||
public int id = -1;
|
||||
public String title = "";
|
||||
public HashMap<Integer,TransportLocation> locations;
|
||||
|
||||
public TransportCategory(){
|
||||
locations = new HashMap<Integer, TransportLocation>();
|
||||
}
|
||||
|
||||
public Vector<TransportLocation> getDefaultLocations() {
|
||||
Vector<TransportLocation> list = new Vector<TransportLocation>();
|
||||
for(TransportLocation loc : locations.values())
|
||||
@@ -47,4 +53,53 @@ public class TransportCategory {
|
||||
}
|
||||
compound.setTag("CategoryLocations", locs);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void addLocation(String name) {
|
||||
int id = TransportController.getInstance().getUniqueIdLocation();
|
||||
TransportLocation location = new TransportLocation();
|
||||
location.id = id;
|
||||
location.name = name;
|
||||
location.category = this;
|
||||
|
||||
TransportController.getInstance().setLocation(location);
|
||||
}
|
||||
|
||||
public ITransportLocation getLocation(String name) {
|
||||
TransportLocation location = null;
|
||||
for (TransportLocation l : locations.values()) {
|
||||
if (l.getName().equals(name)) {
|
||||
location = l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
public void removeLocation(String name) {
|
||||
int id = -1;
|
||||
for (Map.Entry<Integer,TransportLocation> entry : locations.entrySet()) {
|
||||
if (entry.getValue().getName().equals(name)) {
|
||||
id = entry.getKey();;
|
||||
locations.remove(entry.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (id >= 0) {
|
||||
TransportController.getInstance().removeLocation(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.TransportController;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation;
|
||||
|
||||
public class TransportLocation {
|
||||
public class TransportLocation implements ITransportLocation {
|
||||
public int id = -1;
|
||||
public String name = "default name";
|
||||
public double posX;
|
||||
@@ -41,4 +43,54 @@ public class TransportLocation {
|
||||
public boolean isDefault() {
|
||||
return type == 1;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setDimension(int dimension) {
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public int getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y, int z) {
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.posZ = z;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return posX;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return posY;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return posZ;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
TransportController.getInstance().saveLocation(this.category.id, this);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user