use of com.solinia.solinia.Models.SoliniaSpawnGroup in project solinia3-core by mixxit.
the class SoliniaSpawnGroupFactory method Create.
public static void Create(String spawngroupname, int npcid, Location location, boolean operatorCreated) throws CoreStateInitException, SoliniaSpawnGroupCreationException {
if (StateManager.getInstance().getConfigurationManager().getSpawnGroup(spawngroupname.toUpperCase()) != null)
throw new SoliniaSpawnGroupCreationException("Spawngroup already exists");
if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null)
throw new SoliniaSpawnGroupCreationException("NPC does not exist");
SoliniaSpawnGroup sg = new SoliniaSpawnGroup();
sg.setId(StateManager.getInstance().getConfigurationManager().getNextSpawnGroupId());
sg.setName(spawngroupname.toUpperCase());
sg.setNpcid(npcid);
sg.setLocation(location);
sg.setRespawntime(900);
sg.setOperatorCreated(operatorCreated);
StateManager.getInstance().getConfigurationManager().addSpawnGroup(sg);
}
use of com.solinia.solinia.Models.SoliniaSpawnGroup in project solinia3-core by mixxit.
the class JsonSpawnGroupRepository method commit.
@Override
public void commit() {
// TODO Auto-generated method stub
GsonBuilder gsonbuilder = new GsonBuilder();
// gsonbuilder.setPrettyPrinting();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaSpawnGroupTypeAdapterFactory(SoliniaSpawnGroup.class));
Gson gson = gsonbuilder.create();
String jsonOutput = gson.toJson(spawngroups.values(), new TypeToken<List<SoliniaSpawnGroup>>() {
}.getType());
try {
File file = new File(filePath);
if (!file.exists())
file.createNewFile();
FileOutputStream fileOut = new FileOutputStream(file);
OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
outWriter.append(jsonOutput);
outWriter.close();
fileOut.close();
System.out.println("Commited " + spawngroups.size() + " spawngroups");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.solinia.solinia.Models.SoliniaSpawnGroup in project solinia3-core by mixxit.
the class JsonSpawnGroupRepository method reload.
@Override
public void reload() {
List<ISoliniaSpawnGroup> file = new ArrayList<ISoliniaSpawnGroup>();
try {
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeAdapterFactory(new ISoliniaSpawnGroupTypeAdapterFactory(SoliniaSpawnGroup.class));
Gson gson = gsonbuilder.create();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaSpawnGroup>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
spawngroups.clear();
for (ISoliniaSpawnGroup i : file) {
spawngroups.put(i.getId(), i);
}
System.out.println("Reloaded " + spawngroups.size() + " spawngroups");
}
Aggregations