Package com.massivecraft.mcore.xlib.gson

Examples of com.massivecraft.mcore.xlib.gson.JsonObject


  @Override
  public Map<PS, TerritoryAccess> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
  {
    Map<PS, TerritoryAccess> ret = new ConcurrentSkipListMap<PS, TerritoryAccess>();
   
    JsonObject jsonObject = json.getAsJsonObject();
   
    for (Entry<String, JsonElement> entry : jsonObject.entrySet())
    {
      String[] ChunkCoordParts = entry.getKey().split("[,\\s]+");
      int chunkX = Integer.parseInt(ChunkCoordParts[0]);
      int chunkZ = Integer.parseInt(ChunkCoordParts[1]);
      PS chunk = PS.valueOf(chunkX, chunkZ);
View Full Code Here


  }

  @Override
  public JsonElement serialize(Map<PS, TerritoryAccess> src, Type typeOfSrc, JsonSerializationContext context)
  {
    JsonObject ret = new JsonObject();
   
    for (Entry<PS, TerritoryAccess> entry : src.entrySet())
    {
      PS ps = entry.getKey();
      TerritoryAccess territoryAccess = entry.getValue();
     
      ret.add(ps.getChunkX().toString() + "," + ps.getChunkZ().toString(), context.serialize(territoryAccess, TerritoryAccess.class));
    }
   
    return ret;
  }
View Full Code Here

      String hostFactionId = json.getAsString();
      return TerritoryAccess.valueOf(hostFactionId);
    }

    // Otherwise object
    JsonObject obj = json.getAsJsonObject();

    // Prepare variables
    String hostFactionId = null;
    Boolean hostFactionAllowed = null;
    Set<String> factionIds = null;
    Set<String> playerIds = null;
   
    // Read variables (test old values first)
    JsonElement element = null;
   
    element = obj.get("ID");
    if (element == null) element = obj.get(HOST_FACTION_ID);
    hostFactionId = element.getAsString();
   
    element = obj.get("open");
    if (element == null) element = obj.get(HOST_FACTION_ALLOWED);
    if (element != null) hostFactionAllowed = element.getAsBoolean();
   
    element = obj.get("factions");
    if (element == null) element = obj.get(FACTION_IDS);
    if (element != null) factionIds = context.deserialize(element, SET_OF_STRING_TYPE);
   
    element = obj.get("fplayers");
    if (element == null) element = obj.get(PLAYER_IDS);
    if (element != null) playerIds = context.deserialize(element, SET_OF_STRING_TYPE);
   
    return TerritoryAccess.valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds);
  }
View Full Code Here

    {
      return new JsonPrimitive(src.getHostFactionId());
    }

    // Otherwise object
    JsonObject obj = new JsonObject();
   
    obj.addProperty(HOST_FACTION_ID, src.getHostFactionId());
   
    if (!src.isHostFactionAllowed())
    {
      obj.addProperty(HOST_FACTION_ALLOWED, src.isHostFactionAllowed());
    }
   
    if (!src.getFactionIds().isEmpty())
    {
      obj.add(FACTION_IDS, context.serialize(src.getFactionIds(), SET_OF_STRING_TYPE));
    }
   
    if (!src.getPlayerIds().isEmpty())
    {
      obj.add(PLAYER_IDS, context.serialize(src.getPlayerIds(), SET_OF_STRING_TYPE));
    }

    return obj;
  }
View Full Code Here

    if (src == null)
    {
      return JsonNull.INSTANCE;
    }
   
    JsonObject ret = new JsonObject();
   
    String type = src.getClass().getCanonicalName();
    ret.addProperty(TYPE, type);
   
    JsonElement value = context.serialize(src);
    ret.add(VALUE, value);
   
    return ret;
  }
View Full Code Here

    if (!json.isJsonObject())
    {
      throw new JsonParseException("A polymorph must be an object.");
    }
   
    JsonObject jsonObject = json.getAsJsonObject();
   
    if (!jsonObject.has(TYPE))
    {
      throw new JsonParseException("A polymorph must be have a \""+TYPE+"\" field.");
    }
   
    if (!jsonObject.has(VALUE))
    {
      throw new JsonParseException("A polymorph must be have a \"+VALUE+\" field.");
    }
   
    String type = ((JsonPrimitive)jsonObject.get(TYPE)).getAsString();
   
    Class<?> typeClass = null;
    try
    {
      typeClass = Class.forName(type);
    }
    catch (ClassNotFoundException e)
    {
      e.printStackTrace();
      throw new JsonParseException(e.getMessage());
    }
    return context.deserialize(jsonObject.get(VALUE), typeClass);
  }
View Full Code Here

 
  public static JsonObject toJson(PotionEffect potionEffect)
  {
    if (potionEffect == null) return null;
   
    JsonObject ret = new JsonObject();
   
    ret.addProperty(POTION_EFFECT_ID, potionEffect.getType().getId());
    ret.addProperty(POTION_DURATION, potionEffect.getDuration());
    ret.addProperty(POTION_AMPLIFIER, potionEffect.getAmplifier());
    ret.addProperty(POTION_AMBIENT, potionEffect.isAmbient());
   
    return ret;
  }
View Full Code Here

  public static PotionEffect fromJson(JsonElement jsonElement)
  {
    if (jsonElement == null) return null;
    if ( ! jsonElement.isJsonObject()) return null;
   
    JsonObject json = jsonElement.getAsJsonObject();
   
    PotionEffectType pet = PotionEffectType.getById(json.get(POTION_EFFECT_ID).getAsInt());
   
    int duration = POTION_DURATION_DEFAULT;
    JsonElement durationElement = json.get(POTION_DURATION);
    if (durationElement != null)
    {
      duration = durationElement.getAsInt();
    }
   
    int amplifier = POTION_AMPLIFIER_DEFAULT;
    JsonElement amplifierElement = json.get(POTION_AMPLIFIER);
    if (amplifierElement != null)
    {
      amplifier = amplifierElement.getAsInt();
    }
   
    boolean ambient = POTION_AMBIENT_DEFAULT;
    JsonElement ambientElement = json.get(POTION_AMBIENT);
    if (ambientElement != null)
    {
      ambient = ambientElement.getAsBoolean();
    }
   
View Full Code Here

    if (stack == null) return null;
    if (stack.getTypeId() == 0) return null;
    if (stack.getAmount() == 0) return null;

    // Create a new JsonObject
    JsonObject json = new JsonObject();

    // Transfer data from stack to json
    transferAll(stack, json, true);

    return json;
View Full Code Here

    // Check for "nothing"
    if (jsonElement == null) return null;

    // Must be a JsonObject
    if (jsonElement.isJsonObject() == false) return null;
    JsonObject json = jsonElement.getAsJsonObject();

    // Create a new ItemStack
    ItemStack stack = createItemStack();

    // Transfer data from json to stack
View Full Code Here

TOP

Related Classes of com.massivecraft.mcore.xlib.gson.JsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.