Пример #1
0
 @Override
 public QuestTaskReputation.ReputationSetting read(JsonReader in) throws IOException {
   in.beginObject();
   Reputation reputation = null;
   int low = Integer.MIN_VALUE, high = Integer.MIN_VALUE;
   boolean inverted = false;
   while (in.hasNext()) {
     String name = in.nextName();
     if (name.equalsIgnoreCase(REPUTATION)) {
       reputation = Reputation.getReputation(in.nextInt());
     } else if (name.equalsIgnoreCase(UPPER)) {
       high = in.nextInt();
     } else if (name.equalsIgnoreCase(LOWER)) {
       low = in.nextInt();
     } else if (name.equalsIgnoreCase(INVERTED)) {
       inverted = in.nextBoolean();
     }
   }
   if (reputation == null) {
     return null;
   }
   ReputationMarker lower = null, upper = null;
   if (low != Integer.MIN_VALUE) lower = reputation.getMarker(low);
   if (high != Integer.MIN_VALUE) upper = reputation.getMarker(high);
   in.endObject();
   return new QuestTaskReputation.ReputationSetting(reputation, lower, upper, inverted);
 }
Пример #2
0
 @Override
 public QuestTaskLocation.Location read(JsonReader in) throws IOException {
   in.beginObject();
   QuestTaskLocation.Location result = ((QuestTaskLocation) TASK).new Location();
   while (in.hasNext()) {
     String name = in.nextName();
     if (name.equalsIgnoreCase(NAME)) {
       ReflectionHelper.setPrivateValue(
           QuestTaskLocation.Location.class, result, in.nextString(), NAME);
     } else if (name.equalsIgnoreCase(X)) {
       result.setX(in.nextInt());
     } else if (name.equalsIgnoreCase(Y)) {
       result.setY(in.nextInt());
     } else if (name.equalsIgnoreCase(Z)) {
       result.setZ(in.nextInt());
     } else if (name.equalsIgnoreCase(DIM)) {
       result.setDimension(in.nextInt());
     } else if (name.equalsIgnoreCase(RADIUS)) {
       result.setRadius(in.nextInt());
     } else if (name.equalsIgnoreCase(ICON)) {
       ReflectionHelper.setPrivateValue(
           QuestTaskLocation.Location.class,
           result,
           MinecraftAdapter.ITEM_STACK.read(in),
           ICON);
     } else if (name.equalsIgnoreCase(VISIBLE)) {
       result.setVisible(QuestTaskLocation.Visibility.valueOf(in.nextString()));
     }
   }
   in.endObject();
   return result;
 }
Пример #3
0
 @Override
 public Calendar read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   in.beginObject();
   int year = 0;
   int month = 0;
   int dayOfMonth = 0;
   int hourOfDay = 0;
   int minute = 0;
   int second = 0;
   while (in.peek() != JsonToken.END_OBJECT) {
     String name = in.nextName();
     int value = in.nextInt();
     if (YEAR.equals(name)) {
       year = value;
     } else if (MONTH.equals(name)) {
       month = value;
     } else if (DAY_OF_MONTH.equals(name)) {
       dayOfMonth = value;
     } else if (HOUR_OF_DAY.equals(name)) {
       hourOfDay = value;
     } else if (MINUTE.equals(name)) {
       minute = value;
     } else if (SECOND.equals(name)) {
       second = value;
     }
   }
   in.endObject();
   return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
 }
Пример #4
0
 @Override
 public Student read(JsonReader reader) throws IOException {
   Student student = new Student();
   reader.beginObject();
   String fieldname = null;
   while (reader.hasNext()) {
     JsonToken token = reader.peek();
     if (token.equals(JsonToken.NAME)) {
       // get the current token
       fieldname = reader.nextName();
     }
     if ("name".equals(fieldname)) {
       // move to next token
       token = reader.peek();
       student.setName(reader.nextString());
     }
     if ("rollNo".equals(fieldname)) {
       // move to next token
       token = reader.peek();
       student.setRollNo(reader.nextInt());
     }
   }
   reader.endObject();
   return student;
 }
Пример #5
0
 @Override
 public QuestTaskItems.ItemRequirement read(JsonReader in) throws IOException {
   in.beginObject();
   ItemStack item = null;
   Fluid fluid = null;
   int required = 1;
   ItemPrecision precision = ItemPrecision.PRECISE;
   while (in.hasNext()) {
     String next = in.nextName();
     if (next.equalsIgnoreCase(ITEM)) {
       item = MinecraftAdapter.ITEM_STACK.read(in);
     } else if (next.equalsIgnoreCase(FLUID)) {
       fluid = MinecraftAdapter.FLUID.read(in);
     } else if (next.equalsIgnoreCase(REQUIRED)) {
       required = in.nextInt();
     } else if (next.equalsIgnoreCase(PRECISION)) {
       ItemPrecision itemPrecision = ItemPrecision.valueOf(in.nextString());
       if (itemPrecision != null) {
         precision = itemPrecision;
       }
     }
   }
   in.endObject();
   QuestTaskItems.ItemRequirement result = null;
   if (item != null) {
     result = new QuestTaskItems.ItemRequirement(item, required);
   } else if (fluid != null) {
     result = new QuestTaskItems.ItemRequirement(fluid, required);
   } else {
     return null;
   }
   result.precision = precision;
   return result;
 }
Пример #6
0
 @Override
 public Quest.ReputationReward read(JsonReader in) throws IOException {
   in.beginObject();
   int rep = 0, val = 0;
   while (in.hasNext()) {
     switch (in.nextName()) {
       case REPUTATION:
         rep = in.nextInt();
         break;
       case VALUE:
         val = in.nextInt();
         break;
     }
   }
   in.endObject();
   Reputation reputation = Reputation.getReputation(rep);
   return reputation != null ? new Quest.ReputationReward(reputation, val) : null;
 }
Пример #7
0
 @Override
 public RepeatInfo read(JsonReader in) throws IOException {
   RepeatType type = RepeatType.NONE;
   int days = 0, hours = 0;
   in.beginObject();
   while (in.hasNext()) {
     switch (in.nextName()) {
       case TYPE:
         type = RepeatType.valueOf(in.nextString());
         break;
       case HOURS:
         hours = in.nextInt();
         break;
       case DAYS:
         days = in.nextInt();
     }
   }
   in.endObject();
   return new RepeatInfo(type, days, hours);
 }
Пример #8
0
 @Override
 public Number read(JsonReader in) throws IOException {
   if (in.peek() == JsonToken.NULL) {
     in.nextNull();
     return null;
   }
   try {
     return in.nextInt();
   } catch (NumberFormatException e) {
     throw new JsonSyntaxException(e);
   }
 }
Пример #9
0
 private static Calendar read(JsonReader jsonreader)
     throws IOException
 {
     if (jsonreader.peek() == JsonToken.NULL)
     {
         jsonreader.nextNull();
         return null;
     }
     jsonreader.beginObject();
     int k1 = 0;
     int j1 = 0;
     int i1 = 0;
     int l = 0;
     int k = 0;
     int j = 0;
     do
     {
         if (jsonreader.peek() == JsonToken.END_OBJECT)
         {
             break;
         }
         String s = jsonreader.nextName();
         int i = jsonreader.nextInt();
         if ("year".equals(s))
         {
             k1 = i;
         } else
         if ("month".equals(s))
         {
             j1 = i;
         } else
         if ("dayOfMonth".equals(s))
         {
             i1 = i;
         } else
         if ("hourOfDay".equals(s))
         {
             l = i;
         } else
         if ("minute".equals(s))
         {
             k = i;
         } else
         if ("second".equals(s))
         {
             j = i;
         }
     } while (true);
     jsonreader.endObject();
     return new GregorianCalendar(k1, j1, i1, l, k, j);
 }
Пример #10
0
 @Override
 public UserRole read(JsonReader in) throws IOException {
   JsonToken jsonToken = in.peek();
   if (jsonToken == JsonToken.NULL) {
     in.nextNull();
     return null;
   } else {
     try {
       return UserRole.values()[in.nextInt()];
     } catch (RuntimeException e) {
       throw new IOException(Messages.INVALID_USER_ROLE, e);
     }
   }
 }
Пример #11
0
 private String nextValue() {
   try {
     tokenType = jsonReader.peek();
     JsonObject peek = stackObj.peek();
     String valueType = peek.getValueType();
     if (!validateArgumentTypes(tokenType, valueType)) {
       log.error(
           "Value type miss match, Expected value type - '"
               + valueType
               + "', but found - '"
               + tokenType.toString()
               + "'");
       throw new IllegalArgumentException(
           "Value type miss match, Expected value type - '"
               + valueType
               + "', but found - '"
               + tokenType.toString()
               + "'");
     }
     if (tokenType == JsonToken.STRING) {
       value = jsonReader.nextString();
     } else if (tokenType == JsonToken.BOOLEAN) {
       value = String.valueOf(jsonReader.nextBoolean());
     } else if (tokenType == JsonToken.NUMBER) {
       if (valueType.equals("int")) {
         value = String.valueOf(jsonReader.nextInt());
       } else if (valueType.equals("long")) {
         value = String.valueOf(jsonReader.nextLong());
       } else if (valueType.equals("double")) {
         value = String.valueOf(jsonReader.nextDouble());
       } else if (valueType.equals("float")) {
         value = String.valueOf(jsonReader.nextDouble());
       }
     } else if (tokenType == JsonToken.NULL) {
       jsonReader.nextNull();
       value = null;
     } else {
       log.error("Couldn't read the value, Illegal state exception");
       throw new RuntimeException("Couldn't read the value, Illegal state exception");
     }
   } catch (IOException e) {
     log.error("IO error while reading json stream");
     throw new RuntimeException("IO error while reading json stream");
   }
   return value;
 }
Пример #12
0
 @Override
 public QuestTaskMob.Mob read(JsonReader in) throws IOException {
   in.beginObject();
   QuestTaskMob.Mob result = ((QuestTaskMob) TASK).new Mob();
   while (in.hasNext()) {
     String name = in.nextName();
     if (name.equalsIgnoreCase(NAME)) {
       result.setName(in.nextString());
     } else if (name.equalsIgnoreCase(ICON)) {
       result.setIcon(MinecraftAdapter.ITEM_STACK.read(in));
     } else if (name.equalsIgnoreCase(MOB)) {
       result.setMob(in.nextString());
     } else if (name.equalsIgnoreCase(EXACT)) {
       result.setExact(in.nextBoolean());
     } else if (name.equalsIgnoreCase(KILLS)) {
       result.setCount(in.nextInt());
     }
   }
   in.endObject();
   return result;
 }
Пример #13
0
        public BitSet read(JsonReader in) throws IOException {
          if (in.peek() == JsonToken.NULL) {
            in.nextNull();
            return null;
          }

          BitSet bitset = new BitSet();
          in.beginArray();
          int i = 0;
          JsonToken tokenType = in.peek();
          while (tokenType != JsonToken.END_ARRAY) {
            boolean set;
            switch (tokenType) {
              case NUMBER:
                set = in.nextInt() != 0;
                break;
              case BOOLEAN:
                set = in.nextBoolean();
                break;
              case STRING:
                String stringValue = in.nextString();
                try {
                  set = Integer.parseInt(stringValue) != 0;
                } catch (NumberFormatException e) {
                  throw new JsonSyntaxException(
                      "Error: Expecting: bitset number value (1, 0), Found: " + stringValue);
                }
                break;
              default:
                throw new JsonSyntaxException("Invalid bitset value type: " + tokenType);
            }
            if (set) {
              bitset.set(i);
            }
            ++i;
            tokenType = in.peek();
          }
          in.endArray();
          return bitset;
        }
 private void checkLfUnion(JsonReader jReader, String keyName, JsonToken peek) throws IOException {
   if (keyName.equals("lfunion1")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.NUMBER, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion2")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.NUMBER, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion3")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.STRING, peek);
     jReader.nextInt();
   } else if (keyName.equals("lfunion4")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.BOOLEAN, peek);
     jReader.nextBoolean();
   } else if (keyName.equals("lfunion5")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.STRING, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion6")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.STRING, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion7")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.STRING, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion8")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.STRING, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion9")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.STRING, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion10")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.STRING, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion11")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.NUMBER, peek);
     jReader.nextString();
   } else if (keyName.equals("lfunion12")) {
     assertEquals("Key " + keyName + " has incorrect type", JsonToken.BOOLEAN, peek);
     jReader.nextBoolean();
   }
 }
 @Override
 public Binding read(JsonReader reader) throws IOException {
   Integer index = null;
   Object value = null;
   SqlDataType type = null;
   while (true) {
     JsonToken token = reader.peek();
     switch (token) {
       case BEGIN_ARRAY:
       case END_ARRAY:
         throw new IllegalArgumentException("arrays are not supported as a binding");
       case BEGIN_OBJECT:
         reader.beginObject();
         break;
       case BOOLEAN:
         value = reader.nextBoolean();
         return new Binding(null, value, null);
       case END_DOCUMENT:
         break;
       case END_OBJECT:
         reader.endObject();
         return new Binding(index, value, type);
       case NAME:
         String name = reader.nextName();
         if (name.equalsIgnoreCase("index")) {
           index = reader.nextInt();
         } else if (name.equalsIgnoreCase("value")) {
           switch (reader.peek()) {
             case BEGIN_ARRAY:
             case END_ARRAY:
               throw new IllegalArgumentException("arrays are not supported as a value");
             case BEGIN_OBJECT:
               break;
             case BOOLEAN:
               value = reader.nextBoolean();
               break;
             case END_DOCUMENT:
               break;
             case END_OBJECT:
               break;
             case NAME:
               break;
             case NULL:
               break;
             case NUMBER:
               value = readNumber(reader);
               break;
             case STRING:
               value = reader.nextString();
               break;
             default:
               break;
           }
         } else if (name.equalsIgnoreCase("type")) {
           type = SqlDataType.lookup(reader.nextString());
         }
         break;
       case NULL:
         reader.nextNull();
         return null;
       case NUMBER:
         value = readNumber(reader);
         return new Binding(null, value, null);
       case STRING:
         value = reader.nextString();
         return new Binding(null, value, null);
       default:
         break;
     }
   }
 }
Пример #16
0
 @Override
 public QuestTask read(JsonReader in) throws IOException {
   in.beginObject();
   if (!in.nextName().equalsIgnoreCase(TYPE)) {
     throw new IOException("Tasks *MUST* start with the type");
   }
   String task = in.nextString();
   TaskType type = TaskType.valueOf(task);
   if (type == null) {
     throw new IOException("Invalid Task Type: " + task);
   }
   TASK = type.addTask(QUEST);
   while (in.hasNext()) {
     String name = in.nextName();
     if (name.equalsIgnoreCase(DESCRIPTION)) {
       TASK.description = in.nextString();
     } else if (name.equalsIgnoreCase(LONG_DESCRIPTION)) {
       TASK.setLongDescription(in.nextString());
     } else if (TASK instanceof QuestTaskItems && name.equalsIgnoreCase(ITEMS)) {
       List<QuestTaskItems.ItemRequirement> list = new ArrayList<>();
       in.beginArray();
       while (in.hasNext()) {
         QuestTaskItems.ItemRequirement entry = ITEM_REQUIREMENT_ADAPTER.read(in);
         if (entry != null) list.add(entry);
       }
       in.endArray();
       ((QuestTaskItems) TASK)
           .setItems(list.toArray(new QuestTaskItems.ItemRequirement[list.size()]));
     } else if (TASK instanceof QuestTaskDeath && name.equalsIgnoreCase(DEATHS)) {
       int death = in.nextInt();
       ((QuestTaskDeath) TASK).setDeaths(death);
     } else if (TASK instanceof QuestTaskLocation && name.equalsIgnoreCase(LOCATIONS)) {
       List<QuestTaskLocation.Location> list = new ArrayList<QuestTaskLocation.Location>();
       in.beginArray();
       while (in.hasNext()) {
         QuestTaskLocation.Location entry = LOCATION_ADAPTER.read(in);
         if (entry != null) list.add(entry);
       }
       in.endArray();
       ((QuestTaskLocation) TASK).locations =
           list.toArray(new QuestTaskLocation.Location[list.size()]);
     } else if (TASK instanceof QuestTaskMob && name.equalsIgnoreCase(MOBS)) {
       List<QuestTaskMob.Mob> list = new ArrayList<QuestTaskMob.Mob>();
       in.beginArray();
       while (in.hasNext()) {
         QuestTaskMob.Mob entry = MOB_ADAPTER.read(in);
         if (entry != null) list.add(entry);
       }
       in.endArray();
       ((QuestTaskMob) TASK).mobs = list.toArray(new QuestTaskMob.Mob[list.size()]);
     } else if (TASK instanceof QuestTaskReputation && name.equalsIgnoreCase(REPUTATION)) {
       List<QuestTaskReputation.ReputationSetting> list =
           new ArrayList<QuestTaskReputation.ReputationSetting>();
       in.beginArray();
       while (in.hasNext()) {
         list.add(REPUTATION_ADAPTER.read(in));
       }
       in.endArray();
       ReflectionHelper.setPrivateValue(
           QuestTaskReputation.class,
           (QuestTaskReputation) TASK,
           list.toArray(new QuestTaskReputation.ReputationSetting[list.size()]),
           "settings");
     } else if (name.equalsIgnoreCase(KILLS) && TASK instanceof QuestTaskReputationKill) {
       ((QuestTaskReputationKill) TASK).setKills(in.nextInt());
     }
   }
   in.endObject();
   type.addTaskData(QUEST);
   return null;
 }
Пример #17
0
 @Override
 public Quest read(JsonReader in) throws IOException {
   int ID_OFFSET = Quest.size();
   QUEST = new Quest(ID_OFFSET, "", "", 0, 0, false);
   List<Integer> requirement = new ArrayList<>(), options = new ArrayList<>();
   in.beginObject();
   while (in.hasNext()) {
     switch (in.nextName()) {
       case NAME:
         QUEST.setName(in.nextString());
         break;
       case DESCRIPTION:
         QUEST.setDescription(in.nextString());
         break;
       case X:
         ReflectionHelper.setPrivateValue(Quest.class, QUEST, in.nextInt(), X);
         break;
       case Y:
         ReflectionHelper.setPrivateValue(Quest.class, QUEST, in.nextInt(), Y);
         break;
       case TRIGGER_TASKS:
         QUEST.setTriggerTasks(in.nextInt());
         break;
       case PARENT_REQUIREMENT:
         QUEST.setParentRequirementCount(in.nextInt());
         break;
       case BIG_ICON:
         QUEST.setBigIcon(in.nextBoolean());
         break;
       case ICON:
         QUEST.setIcon(MinecraftAdapter.ITEM_STACK.read(in));
         break;
       case REQUIREMENTS:
         in.beginArray();
         while (in.hasNext()) {
           requirement.add(in.nextInt() + QUEST_ID);
         }
         in.endArray();
         break;
       case OPTIONS:
         in.beginArray();
         while (in.hasNext()) {
           options.add(in.nextInt() + QUEST_ID);
         }
         in.endArray();
         break;
       case REPEAT:
         QUEST.setRepeatInfo(REPEAT_INFO_ADAPTER.read(in));
         break;
       case TRIGGER:
         QUEST.setTriggerType(TriggerType.valueOf(in.nextString()));
         break;
       case TASKS:
         in.beginArray();
         while (in.hasNext()) {
           QuestTask task = TASK_ADAPTER.read(in);
           if (task != null) {
             QUEST.getTasks().add(task);
           }
         }
         in.endArray();
         break;
       case REWARDS:
         ReflectionHelper.setPrivateValue(
             Quest.class, QUEST, readItemStackArray(in), REWARDS);
         break;
       case REWARDS_CHOICE:
         ReflectionHelper.setPrivateValue(
             Quest.class, QUEST, readItemStackArray(in), REWARDS_CHOICE);
         break;
       case REWARDS_REPUTATION:
         in.beginArray();
         List<Quest.ReputationReward> reputationRewards = new ArrayList<>();
         while (in.hasNext()) {
           Quest.ReputationReward reward = REPUTATION_REWARD_ADAPTER.read(in);
           if (reward != null) reputationRewards.add(reward);
         }
         QUEST.setReputationRewards(reputationRewards);
         in.endArray();
         break;
     }
   }
   in.endObject();
   if (!QUEST.getName().isEmpty()) {
     requirementMapping.put(QUEST, requirement);
     optionMapping.put(QUEST, options);
     return QUEST;
   }
   QuestLine.getActiveQuestLine().quests.remove(QUEST.getId());
   return null;
 }
Пример #18
0
 @Override
 public CustomInt read(JsonReader in) throws IOException {
   return new CustomInt(in.nextInt());
 }