List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:ccm.pay2spawn.permissions.Group.java
License:Open Source License
public JsonElement toJson() { JsonObject root = new JsonObject(); root.addProperty("name", getName()); root.addProperty("parent", getParent()); JsonArray nodes = new JsonArray(); for (Node node : this.nodes) nodes.add(new JsonPrimitive(node.toString())); root.add("nodes", nodes); return root;//from w ww .j av a 2 s. com }
From source file:ccm.pay2spawn.permissions.PermissionsDB.java
License:Open Source License
public void save() { try {/*from w ww .java 2s. c o m*/ File file = getFile(); if (!file.exists()) //noinspection ResultOfMethodCallIgnored file.createNewFile(); JsonObject rootObject = new JsonObject(); JsonArray players = new JsonArray(); for (Player player : playerDB.values()) players.add(player.toJson()); rootObject.add("players", players); JsonArray groups = new JsonArray(); for (Group group : groupDB.values()) groups.add(group.toJson()); rootObject.add("groups", groups); BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.write(GSON.toJson(rootObject)); bw.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ccm.pay2spawn.permissions.PermissionsDB.java
License:Open Source License
public void load() throws IOException { File file = getFile();//w w w . j a v a 2 s . c o m if (file.exists()) { JsonObject rootObject = JSON_PARSER.parse(new FileReader(file)).getAsJsonObject(); for (JsonElement element : rootObject.getAsJsonArray("players")) { Player player = new Player(element.getAsJsonObject()); playerDB.put(player.getName(), player); } for (JsonElement element : rootObject.getAsJsonArray("groups")) { Group group = new Group(element.getAsJsonObject()); groupDB.put(group.getName(), group); } } else { //noinspection ResultOfMethodCallIgnored file.createNewFile(); JsonObject rootObject = new JsonObject(); rootObject.add("players", new JsonArray()); rootObject.add("groups", new JsonArray()); BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.write(GSON.toJson(rootObject)); bw.close(); } }
From source file:ccm.pay2spawn.permissions.Player.java
License:Open Source License
public JsonElement toJson() { JsonObject root = new JsonObject(); root.addProperty("name", getName()); JsonArray groups = new JsonArray(); for (String group : this.getGroups()) groups.add(new JsonPrimitive(group)); root.add("groups", groups); JsonArray nodes = new JsonArray(); for (Node node : this.overrideNodes) nodes.add(new JsonPrimitive(node.toString())); root.add("overrides", nodes); return root;/* www .j a v a2 s .c o m*/ }
From source file:ccm.pay2spawn.types.guis.EntityTypeGui.java
License:Open Source License
public void setupListeners() { testButton.addActionListener(new ActionListener() { @Override// w ww . j a va 2 s . c om public void actionPerformed(ActionEvent e) { updateJson(); TestMessage.sendToServer(name, data); } }); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateJson(); if (superGui == null) Configurator.instance.callback(rewardID, name, data); else superGui.callback(data); if (clientGui != null) clientGui.close(); dialog.dispose(); } }); parseFromJsonButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { data = JSON_PARSER.parse(jsonPane.getText()).getAsJsonObject(); readJson(); jsonPane.setForeground(Color.black); } catch (Exception e1) { jsonPane.setForeground(Color.red); e1.printStackTrace(); } } }); updateJsonButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateJson(); } }); addMobThisEntityButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JsonObject object; if (data.has(RIDING_KEY)) object = data.getAsJsonObject(RIDING_KEY); else object = new JsonObject(); clientGui = new EntityTypeGui(rewardID, name, object, typeMap, instance); } }); }
From source file:ccm.pay2spawn.types.guis.FireworksTypeGui.java
License:Open Source License
@Override public void readJson() { amountTextField.setText(readValue(AMOUNT_KEY, data)); radiusTextField.setText(readValue(RADIUS_KEY, data)); HTMLTextField.setText(readValue(CUSTOMHTML, data)); if (!data.has("tag")) data.add("tag", new JsonObject()); if (!data.getAsJsonObject("tag").has(FIREWORKS_KEY)) data.getAsJsonObject("tag").add(FIREWORKS_KEY, new JsonObject()); if (!data.getAsJsonObject("tag").getAsJsonObject(FIREWORKS_KEY).has(EXPLOSIONS_KEY)) data.getAsJsonObject("tag").getAsJsonObject(FIREWORKS_KEY).add(EXPLOSIONS_KEY, new JsonArray()); fireworks = data.getAsJsonObject("tag").getAsJsonObject(FIREWORKS_KEY); flightMultiplierTextField.setText(readValue(FLIGHT_KEY, fireworks)); String ride = readValue(RIDETHISMOB_KEY, data); dontRidemob.setSelected(ride.equals(FALSE_BYTE) || ride.equals("")); rideThisFireworkRadioButton.setSelected(ride.equals(TRUE_BYTE)); randomlyRideMob.setSelected(ride.startsWith(RANDOM_BOOLEAN)); explosionList.updateUI();//from ww w . j av a 2 s . c o m jsonPane.setText(GSON.toJson(data)); }
From source file:ccm.pay2spawn.types.guis.FireworksTypeGui.java
License:Open Source License
@Override public void setupListeners() { testButton.addActionListener(new ActionListener() { @Override//from w w w . ja v a2s . c o m public void actionPerformed(ActionEvent e) { updateJson(); TestMessage.sendToServer(name, data); } }); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateJson(); Configurator.instance.callback(rewardID, name, data); dialog.dispose(); } }); parseFromJsonButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { data = JSON_PARSER.parse(jsonPane.getText()).getAsJsonObject(); readJson(); jsonPane.setForeground(Color.black); } catch (Exception e1) { jsonPane.setForeground(Color.red); e1.printStackTrace(); } } }); updateJsonButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateJson(); } }); importFireworkStartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NbtRequestMessage.requestFirework(instance); } }); addExplosionManuallyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new ExplosionGui(-1, new JsonObject(), instance, typeMap); } }); explosionList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { new ExplosionGui(explosionList.getSelectedIndex(), fireworks.getAsJsonArray(EXPLOSIONS_KEY) .get(explosionList.getSelectedIndex()).getAsJsonObject(), instance, typeMap); } } }); }
From source file:ccm.pay2spawn.types.guis.RandomItemTypeGui.java
License:Open Source License
@Override public void updateJson() { if (!Strings.isNullOrEmpty(itemNameField.getText())) { if (!data.has(TAG_KEY)) data.add(TAG_KEY, new JsonObject()); if (!data.getAsJsonObject(TAG_KEY).has(DISPLAY_KEY)) data.getAsJsonObject(TAG_KEY).add(DISPLAY_KEY, new JsonObject()); storeValue(NAME_KEY, data.getAsJsonObject(TAG_KEY).getAsJsonObject(DISPLAY_KEY), itemNameField.getText()); }//from www . j a va 2 s . c o m if (!Strings.isNullOrEmpty(HTMLTextField.getText())) storeValue(CUSTOMHTML, data, HTMLTextField.getText()); jsonPane.setText(GSON.toJson(data)); }
From source file:ccm.pay2spawn.util.Helper.java
License:Open Source License
/** * Fill in variables from a donation//from w ww . j ava 2 s .c om * * @param dataToFormat data to be formatted * @param donation the donation data * * @return the fully var-replaced JsonElement */ public static JsonElement formatText(JsonElement dataToFormat, Donation donation, Reward reward) { if (dataToFormat.isJsonPrimitive() && dataToFormat.getAsJsonPrimitive().isString()) { return new JsonPrimitive(Helper.formatText(dataToFormat.getAsString(), donation, reward)); } if (dataToFormat.isJsonArray()) { JsonArray out = new JsonArray(); for (JsonElement element : dataToFormat.getAsJsonArray()) { out.add(formatText(element, donation, reward)); } return out; } if (dataToFormat.isJsonObject()) { JsonObject out = new JsonObject(); for (Map.Entry<String, JsonElement> entity : dataToFormat.getAsJsonObject().entrySet()) { out.add(entity.getKey(), Helper.formatText(entity.getValue(), donation, reward)); } return out; } return dataToFormat; }
From source file:ccm.pay2spawn.util.JsonNBTHelper.java
License:Open Source License
public static JsonObject parseNBT(NBTTagCompound compound) { JsonObject jsonObject = new JsonObject(); for (Object object : compound.func_150296_c()) { jsonObject.add(object.toString(), parseNBT(compound.getTag(object.toString()))); }/* w w w. j av a 2 s . c o m*/ return jsonObject; }