readIndex(File indexFile) {
}
gotoAtEnd = index.contains(GOTO_AT_END) ? index.getInt(GOTO_AT_END, 0) : null;
adminLengths = index.getBoolean(ADMIN_LENGTHS, false);
+ shippedPhasesRecorded = index.contains(SHIPPED_PHASES);
+ shippedPhases = new LinkedHashSet<>(index.getStringList(SHIPPED_PHASES));
return entries;
}
+ /**
+ * Adds phases that are new in this addon version to an existing index. An
+ * index belongs to the server, so an addon upgrade never replaces it - without
+ * this, phases shipped by later versions would never appear on servers that
+ * already have an index.
+ *
+ * A shipped phase is added when the index has no phase with its file or name
+ * and it is not in {@link #shippedPhases}, so phases an admin removed are
+ * never brought back. Indexes written before {@link #shippedPhases} existed
+ * treat every shipped phase without an {@code addedIn} tag as already offered.
+ * A new phase goes after the nearest shipped phase above it that the index
+ * has, and its files are copied from the jar.
+ *
+ * @param entries index entries, updated in place
+ * @return true if the entries or the offered phases changed
+ */
+ boolean addNewShippedPhases(List entries) {
+ boolean changed = false;
+ String previous = null;
+ for (Map, ?> map : readShippedIndex()) {
+ PhaseIndexEntry shipped = PhaseIndexEntry.fromMap(map);
+ if (shipped == null) {
+ continue;
+ }
+ String file = shipped.getFile();
+ boolean offered = shippedPhases.contains(file) || (!shippedPhasesRecorded && !map.containsKey(ADDED_IN));
+ boolean inIndex = entries.stream().anyMatch(en -> en.getFile().equals(file)
+ || (en.getName() != null && en.getName().equalsIgnoreCase(shipped.getName())));
+ if (!inIndex && !offered) {
+ entries.add(positionAfter(entries, previous), shipped);
+ restorePhaseFileFromJar(file);
+ addon.log("Phase index: added new phase " + shipped.getName()
+ + " from this version of the addon. Move or disable it with /oba phases.");
+ inIndex = true;
+ }
+ if (inIndex) {
+ previous = file;
+ }
+ changed |= shippedPhases.add(file);
+ }
+ return changed;
+ }
+
+ /**
+ * @return the phase entries of the index shipped in the addon jar, or an
+ * empty list if the jar has none
+ */
+ private List