Code:
package godzhell.model.npcs;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
public class NPCSpawns {
/**
* NPCSpawns, each represents a single npc spawn in the server which is held
* within the array {@link #spawns}.
*
* This was based off of Galkon's ItemDefinitions, therefore it will be heavily
* similar in a lot of ways.
*
* @Author Jesse (Sk8rdude461)
* @Author Galkon
*/
/**
* All the npc spawns.
*/
private static ArrayList<NPCSpawns> spawns;
/**
* The Id of the npc. Commonly referred to as npcType.
*/
private int npcId;
/**
* The home x-pos to the npc
*/
private int xPos;
/**
* The home y-pos to the npc
*/
private int yPos;
/**
* The height level where the npc is spawned
*/
private int height;
/**
* The Walking type for the npc.
*/
private int walkType;
/**
* The health(Constitution) of the npc.
*/
private int health;
/**
* The highest possible hit for the npc.
*/
private int maxHit;
/**
* The attack level of the npc.
*/
private int attack;
/**
* The defence level of the npc.
*/
private int defence;
private int combatLevel;
/**
* Extra info I added so you can tell where the npc is spawned.
*/
private String name;
public NPCSpawns(int npcid, int xPos, int yPos, int height, int walkType, int health, int maxHit, int attack,
int defence, int combatLevel, String name) {
this.npcId = npcid;
this.xPos = xPos;
this.yPos = yPos;
this.height = height;
this.walkType = walkType;
this.health = health;
this.maxHit = maxHit;
this.attack = attack;
this.defence = defence;
this.combatLevel = combatLevel;
this.name = name;
}
public static NPCSpawns defaultNPC() {
try {
NPCSpawns npc = new NPCSpawns(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "New NPC");
npc.setName("New NPC");
System.out.println("NPC Made!");
return npc;
} catch (NullPointerException e) {
return null;
}
}
/**
* Gets the npc spawns
*
* @Return spawns
*/
public static ArrayList<NPCSpawns> getNPCSpawns() {
return spawns;
}
/**
* Sets the npc spawns
*
* @Param npcSpawns
* the NPCSpawns to be set.
*/
public static void setNPCSpawns(ArrayList<NPCSpawns> npcSpawns) {
NPCSpawns.spawns = npcSpawns;
}
/**
* Loading the NPCSpawns.
*
* @Param file
* The file to be read
* @ThroWs java.io.FileNotFoundException
*/
public static void loadNPCSpawns() throws JsonIOException, JsonSyntaxException, FileNotFoundException {
Gson gson = new Gson();
long start = System.currentTimeMillis();
System.out.println("Loading NPC spawns...");
try (FileReader reader = new FileReader("./data/json/npc-spawns.json")) {
setNPCSpawns(gson.fromJson(reader, new TypeToken<ArrayList<NPCSpawns>>() {
}.getType()));
} catch (IOException e) {
e.printStackTrace();
System.out.println("Failed to load NPC spawns!");
} finally {
System.out.println("Loaded " + NPCSpawns.getNPCSpawns().size() + " npc spawns in "
+ (System.currentTimeMillis() - start) + "ms.");
}
}
/**
* @Return npcId
*/
public int getNpcId() {
return npcId;
}
/**
* @Return xPos
*/
public int getXPos() {
return xPos;
}
/**
* @Return yPos
*/
public int getYPos() {
return yPos;
}
/**
* @Return height
*/
public int getHeight() {
return height;
}
/**
* @Return walkType
*/
public int getWalkType() {
return walkType;
}
/**
* @Return health
*/
public int getHealth() {
return health;
}
/**
* @Return maxHit
*/
public int getMaxHit() {
return maxHit;
}
/**
* @Return attack
*/
public int getAttack() {
return attack;
}
/**
* @Return defence
*/
public int getDefence() {
return defence;
}
/**
* @Return combatLevel
*/
public int getCombatLevel() { return combatLevel;}
/**
* @Return name
*/
public String getName() {
return name;
}
public void setNpcId(int npcId) {
this.npcId = npcId;
}
public void setXPos(int xPos) {
this.xPos = xPos;
}
public void setYPos(int yPos) {
this.yPos = yPos;
}
public void setHeight(int height) {
this.height = height;
}
public void setWalkType(int walkType) {
this.walkType = walkType;
}
public void setHealth(int health) {
this.health = health;
}
public void setMaxHit(int maxHit) {
this.maxHit = maxHit;
}
public void setAttack(int attack) {
this.attack = attack;
}
public void setDefence(int defence) {
this.defence = defence;
}
public void setName(String name) {
this.name = name;
}
}
Code:
public static boolean loadAutoSpawn(){
try{
for(int i =0; i < NPCSpawns.getNPCSpawns().size(); i++){
NPCSpawns npc = NPCSpawns.getNPCSpawns().get(i);
newNPC(npc.getNpcId(), npc.getXPos(), npc.getYPos(),npc.getHeight(),
npc.getWalkType(), npc.getHealth(), npc.getMaxHit(), npc.getAttack(),
npc.getDefence());
}
return true;
}catch(Exception e){
return false;
}
https://cdn.discordapp.com/attachmen...pc-spawns.json