use of com.google.gson.reflect.TypeToken in project solinia3-core by mixxit.
the class JsonCraftRepository method commit.
@Override
public void commit() {
// TODO Auto-generated method stub
GsonBuilder gsonbuilder = new GsonBuilder();
// gsonbuilder.setPrettyPrinting();
Gson gson = gsonbuilder.create();
String jsonOutput = gson.toJson(Crafts.values(), new TypeToken<List<SoliniaCraft>>() {
}.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 " + Crafts.size() + " Crafts");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.google.gson.reflect.TypeToken in project solinia3-core by mixxit.
the class JsonAccountClaimRepository method commit.
@Override
public void commit() {
// TODO Auto-generated method stub
GsonBuilder gsonbuilder = new GsonBuilder();
// gsonbuilder.setPrettyPrinting();
Gson gson = gsonbuilder.create();
String jsonOutput = gson.toJson(AccountClaims.values(), new TypeToken<List<SoliniaAccountClaim>>() {
}.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 " + AccountClaims.size() + " AccountClaims");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.google.gson.reflect.TypeToken in project Nukkit by Nukkit.
the class FormWindowCustom method setResponse.
public void setResponse(String data) {
if (data.equals("null")) {
this.closed = true;
return;
}
List<String> elementResponses = new Gson().fromJson(data, new TypeToken<List<String>>() {
}.getType());
// elementResponses.remove(elementResponses.size() - 1); //submit button //maybe mojang removed that?
int i = 0;
HashMap<Integer, FormResponseData> dropdownResponses = new HashMap<>();
HashMap<Integer, String> inputResponses = new HashMap<>();
HashMap<Integer, Float> sliderResponses = new HashMap<>();
HashMap<Integer, FormResponseData> stepSliderResponses = new HashMap<>();
HashMap<Integer, Boolean> toggleResponses = new HashMap<>();
HashMap<Integer, Object> responses = new HashMap<>();
for (String elementData : elementResponses) {
if (i >= content.size()) {
break;
}
Element e = content.get(i);
if (e == null)
break;
if (e instanceof ElementLabel) {
i++;
continue;
}
if (e instanceof ElementDropdown) {
String answer = ((ElementDropdown) e).getOptions().get(Integer.parseInt(elementData));
dropdownResponses.put(i, new FormResponseData(Integer.parseInt(elementData), answer));
responses.put(i, answer);
} else if (e instanceof ElementInput) {
inputResponses.put(i, elementData);
responses.put(i, elementData);
} else if (e instanceof ElementSlider) {
Float answer = Float.parseFloat(elementData);
sliderResponses.put(i, answer);
responses.put(i, answer);
} else if (e instanceof ElementStepSlider) {
String answer = ((ElementStepSlider) e).getSteps().get(Integer.parseInt(elementData));
stepSliderResponses.put(i, new FormResponseData(Integer.parseInt(elementData), answer));
responses.put(i, answer);
} else if (e instanceof ElementToggle) {
Boolean answer = Boolean.parseBoolean(elementData);
toggleResponses.put(i, answer);
responses.put(i, answer);
}
i++;
}
this.response = new FormResponseCustom(responses, dropdownResponses, inputResponses, sliderResponses, stepSliderResponses, toggleResponses);
}
use of com.google.gson.reflect.TypeToken in project Nukkit by Nukkit.
the class BanEntry method fromString.
public static BanEntry fromString(String str) {
Map<String, String> map = new Gson().fromJson(str, new TypeToken<TreeMap<String, String>>() {
}.getType());
BanEntry banEntry = new BanEntry(map.get("name"));
try {
banEntry.setCreationDate(new SimpleDateFormat(format).parse(map.get("creationDate")));
banEntry.setExpirationDate(!map.get("expireDate").equals("Forever") ? new SimpleDateFormat(format).parse(map.get("expireDate")) : null);
} catch (ParseException e) {
Server.getInstance().getLogger().logException(e);
}
banEntry.setSource(map.get("source"));
banEntry.setReason(map.get("reason"));
return banEntry;
}
use of com.google.gson.reflect.TypeToken in project Nukkit by Nukkit.
the class BanList method load.
public void load() {
this.list = new LinkedHashMap<>();
File file = new File(this.file);
try {
if (!file.exists()) {
file.createNewFile();
this.save();
} else {
LinkedList<TreeMap<String, String>> list = new Gson().fromJson(Utils.readFile(this.file), new TypeToken<LinkedList<TreeMap<String, String>>>() {
}.getType());
for (TreeMap<String, String> map : list) {
BanEntry entry = BanEntry.fromMap(map);
this.list.put(entry.getName(), entry);
}
}
} catch (IOException e) {
MainLogger.getLogger().error("Could not load ban list: ", e);
}
}
Aggregations