List of usage examples for com.google.gson JsonObject get
public JsonElement get(String memberName)
From source file:ccm.pay2spawn.types.guis.HelperGuiBase.java
License:Open Source License
public String readValue(String key, JsonObject jsonObject) { if (jsonObject == null || !jsonObject.has(key)) return ""; String string = jsonObject.get(key).getAsString(); return string.substring(string.indexOf(":") + 1); }
From source file:ccm.pay2spawn.types.ItemType.java
License:Open Source License
@Override public String replaceInTemplate(String id, JsonObject jsonObject) { switch (id) { case "stacksize": return jsonObject.get("Count").getAsString().replace("BYTE:", ""); case "itemname": ItemStack is = ItemStack.loadItemStackFromNBT(JsonNBTHelper.parseJSON(jsonObject)); return is.getItem().getItemStackDisplayName(is); }// ww w . j a v a 2 s .co m return id; }
From source file:ccm.pay2spawn.types.LightningType.java
License:Open Source License
@Override public String replaceInTemplate(String id, JsonObject jsonObject) { switch (id) { case "target": switch (Integer.parseInt(jsonObject.get(TYPE_KEY).getAsString().split(":", 2)[1])) { case PLAYER_ENTITY: return "the streamer"; case NEAREST_ENTITY: return "the nearest entity"; case RND_SPOT: return "a random near spot"; case RND_ENTITY: return "a random near entity"; }//from w w w. ja v a2 s .co m } return id; }
From source file:ccm.pay2spawn.types.MusicType.java
License:Open Source License
@Override public String replaceInTemplate(String id, JsonObject jsonObject) { switch (id) { case "song": return jsonObject.get(SOUND_KEY).getAsString().replace(typeMap.get(SOUND_KEY) + ":", ""); }/*from w w w .j av a 2 s . co m*/ return id; }
From source file:ccm.pay2spawn.types.PlayerModificationType.java
License:Open Source License
@Override public String replaceInTemplate(String id, JsonObject jsonObject) { switch (id) { case "type": return Type.values()[Integer.parseInt(jsonObject.get(TYPE_KEY).getAsString().split(":", 2)[1])].name() .toLowerCase();//from w w w . j av a 2 s . c o m case "operation": switch (Integer.parseInt(jsonObject.get(OPERATION_KEY).getAsString().split(":", 2)[1])) { case ADD: return "adding"; case SUBTRACT: return "subtracting"; case SET: return "setting"; case ENABLE: return "enabling it" + (jsonObject.has(AMOUNT_KEY) ? " for" : ""); case DISABLE: return "disabling it" + (jsonObject.has(AMOUNT_KEY) ? " for" : ""); } case "amount": if (jsonObject.has(AMOUNT_KEY)) return NUMBER_FORMATTER .format(Float.parseFloat(jsonObject.get(OPERATION_KEY).getAsString().split(":", 2)[1])); else return ""; } return id; }
From source file:ccm.pay2spawn.types.PotionEffectType.java
License:Open Source License
@Override public String replaceInTemplate(String id, JsonObject jsonObject) { switch (id) { case "effect": PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(JsonNBTHelper.parseJSON(jsonObject)); return effect.getEffectName() + " " + (effect.getAmplifier() + 1); case "duration": return jsonObject.get(DURATION_KEY).getAsString().replace(typeMap.get(DURATION_KEY), ""); }/* ww w. j a v a 2s. c o m*/ return id; }
From source file:ccm.pay2spawn.util.Reward.java
License:Open Source License
public Reward(JsonObject json) { name = json.get("name").getAsString(); amount = json.get("amount").getAsDouble(); message = Helper.formatColors(json.get("message").getAsString()); rewards = json.getAsJsonArray("rewards"); try {/*www . j a va 2s. c o m*/ countdown = json.get("countdown").getAsInt(); } catch (Exception e) { countdown = 0; } /** * To try and catch errors in the config file ASAP */ try { JsonNBTHelper.parseJSON(rewards); } catch (Exception e) { Pay2Spawn.getLogger().warn("ERROR TYPE 2: Error in reward " + name + "'s NBT data."); Pay2Spawn.getLogger().warn(rewards.toString()); throw e; } }
From source file:ccm.pay2spawn.util.Reward.java
License:Open Source License
public String getHTML() throws IOException { StringBuilder sb = new StringBuilder(); for (JsonElement element : rewards) { JsonObject object = element.getAsJsonObject(); if (object.has(CUSTOMHTML) && !Strings.isNullOrEmpty(object.get(CUSTOMHTML).getAsString())) sb.append(object.get(CUSTOMHTML).getAsString()); else/*from w w w. ja v a2s . com*/ sb.append(TypeRegistry.getByName(object.get("type").getAsString()) .getHTML(object.getAsJsonObject("data"))); } return sb.toString(); }
From source file:cd.go.authentication.ldap.executor.IsValidUserRequestExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() { JsonObject jsonObject = GSON.fromJson(request.requestBody(), JsonObject.class); Type type = new TypeToken<AuthConfig>() { }.getType();//from w w w .j a v a 2 s . c o m String usernameToCheck = jsonObject.get(USERNAME).getAsString(); AuthConfig authConfig = GSON.fromJson(jsonObject.get(AUTH_CONFIG).toString(), type); final User found = findUser(usernameToCheck, authConfig); if (found != null) { return new DefaultGoPluginApiResponse(200); } return new DefaultGoPluginApiResponse(404); }
From source file:cd.go.authentication.ldap.model.AuthConfig.java
License:Apache License
public static List<AuthConfig> fromJSONList(String requestBody) { JsonObject jsonObject = GSON.fromJson(requestBody, JsonObject.class); Type type = new TypeToken<List<AuthConfig>>() { }.getType();// w w w. ja va 2 s.c o m return GSON.fromJson(jsonObject.get("auth_configs").toString(), type); }