36 LinkedList<WikiTable>
tables =
new LinkedList<>();
37 String link =
"https://oldschoolrunescape.fandom.com/wiki/Category:Items";
38 Iterator<Definition> iterator = definitions.iterator();
40 while (iterator.hasNext()) {
45 protected void parseDocument(Document document) {
46 Elements infobox = document.select(
".wikitable.infobox");
47 Elements equipment = document.select(
".wikitable.smallpadding");
50 EquipmentType type = EquipmentType.NOT_WIELDABLE;
51 boolean twoHanded = false;
54 for (Element info : infobox) {
55 JsonObject object = new JsonObject();
56 Elements attributes = infobox.select(
"a");
58 String destroyMessage =
"Drop";
60 boolean tradeable = false;
62 for (Element attribute : attributes) {
63 String attr = attribute.attr(
"title");
67 tradeable = attribute.parent().nextElementSibling().text().equalsIgnoreCase(
"Yes");
71 destroyMessage = attribute.parent().nextElementSibling().text();
75 Element element = attribute.parent().nextElementSibling();
76 String alchemy = element.text().replaceAll(
"[^-\\d.]",
"");
77 if (!alchemy.matches(
"-?[0-9]*\\.?[0-9]*")) {
78 alchemy = element.children().last().nextSibling().toString().replaceAll(
"[^-\\d.]",
"");
80 if (!alchemy.isEmpty())
81 weight = Double.parseDouble(alchemy);
85 } catch (Exception ignored) {
86 logger.warn(
"Exception while parsing item [id=" + definition.id +
", name=" + definition.name +
"]", ignored);
91 if (!equipment.isEmpty()) {
92 bonuses = new int[Equipment.SIZE];
94 Elements equipmentInfo = equipment.select(
"td");
96 if (equipmentInfo.size() > idx) {
98 Element attribute = equipmentInfo.get(idx++);
99 if (attribute.attr(
"style").equals(
"text-align: center; width: 35px;")
100 || attribute.attr(
"style").equals(
"text-align: center; width: 30px;")) {
101 bonuses[ind++ % Equipment.SIZE] = Integer.parseInt(attribute.text().replace(
"%",
""));
103 } while (ind < Equipment.SIZE);
106 for (Element attribute : equipment.select(
"img")) {
107 switch (attribute.attr(
"data-image-key")) {
108 case
"Head_slot.png":
109 type = EquipmentType.HELM;
111 case
"Cape_slot.png":
112 type = EquipmentType.CAPE;
114 case
"Weapon_slot.png":
115 type = EquipmentType.WEAPON;
117 case
"Neck_slot.png":
118 type = EquipmentType.AMULET;
120 case
"Ammo_slot.png":
121 type = EquipmentType.ARROWS;
123 case
"Shield_slot.png":
124 type = EquipmentType.SHIELD;
126 case
"Torso_slot.png":
127 type = EquipmentType.BODY;
129 case
"Legs_slot.png":
130 type = EquipmentType.LEGS;
132 case
"Gloves_slot.png":
133 type = EquipmentType.GLOVES;
135 case
"Boots_slot.png":
136 type = EquipmentType.BOOTS;
138 case
"Ring_slot.png":
139 type = EquipmentType.RING;
142 type = EquipmentType.WEAPON;
148 } catch (Exception ignored) {
150 type = EquipmentType.NOT_WIELDABLE;
151 logger.warn(
"Exception while parsing item equipment data [id=" + definition.id +
", name=" + definition.name +
"]", ignored);
154 object.addProperty(
"name", info.select(
"caption").text());
156 if (!destroyMessage.equals(
"Drop"))
157 object.addProperty(
"destroy-message", destroyMessage);
160 object.addProperty(
"tradable", true);
163 object.addProperty(
"two-handed", true);
166 object.addProperty(
"weight", weight);
168 if (type != EquipmentType.NOT_WIELDABLE)
169 object.addProperty(
"equipment-type", type.name());
171 if (bonuses != null) {
172 for (int index = 0; index < BONUS_CONFIG_FIELD_NAMES.length; index++) {
173 String bonusName = BONUS_CONFIG_FIELD_NAMES[index];
174 if (bonuses[index] != 0) {
175 object.addProperty(bonusName, bonuses[index]);
180 if (!table.contains(object)) {