Skip to content

Commit

Permalink
Limit the amount of changelog lines printed to 100. (#5352)
Browse files Browse the repository at this point in the history
* Limit the amount of changelog lines printed to 100.

* Prevent double checks

* Set index at first new version

* Fix up changelog to only display newer versions than the last run
version, make messages more accurate, colour.

Co-authored-by: Llm Dl <LlmDlio@gmail.com>
  • Loading branch information
Warriorrrr and LlmDl authored Oct 9, 2021
1 parent cb88892 commit de181df
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/com/palmergames/bukkit/towny/Towny.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.palmergames.bukkit.towny.utils.SpawnUtil;
import com.palmergames.bukkit.towny.war.common.WarZoneListener;
import com.palmergames.bukkit.util.BukkitTools;
import com.palmergames.bukkit.util.Colors;
import com.palmergames.bukkit.util.Version;
import com.palmergames.util.FileMgmt;
import com.palmergames.util.JavaUtil;
Expand Down Expand Up @@ -652,22 +653,46 @@ private void printChangelogToConsole() {

try {
List<String> changeLog = JavaUtil.readTextFromJar("/ChangeLog.txt");
boolean display = false;
plugin.getLogger().info("------------------------------------");
plugin.getLogger().info("ChangeLog up until v" + getVersion());
int startingIndex = 0;
int linesDisplayed = 0;
String lastVersion = Version.fromString(TownySettings.getLastRunVersion()).toString(); // Parse out any trailing text after the *.*.*.* version, ie "-for-1.12.2".
for (String line : changeLog) { // TODO: crawl from the bottom, then
// past from that index.
if (line.startsWith(lastVersion)) {
display = true;
plugin.getLogger().info("------------------------------------");
plugin.getLogger().info("ChangeLog since v" + lastVersion + ":");

// Go backwards through the changelog to get to the last run version.
for (int i = changeLog.size() - 1; i >= 0; i--) {
if (changeLog.get(i).startsWith(lastVersion)) {
// Go forwards through the changelog to find the next version after the last run version.
for (int j = i + 1; j < changeLog.size(); j++) {
if (!changeLog.get(j).trim().startsWith("-")) {
startingIndex = j;
break;
}
}
break;
}
if (display && line.replaceAll(" ", "").replaceAll("\t", "").length() > 0) {
Bukkit.getLogger().info(line);
}

if (startingIndex != 0) {
for (int i = startingIndex; i < changeLog.size(); i++) {
if (linesDisplayed > 100) {
plugin.getLogger().info(Colors.Yellow + "<snip>");
plugin.getLogger().info(Colors.Yellow + "Changelog continues for another " + (changeLog.size() - (startingIndex + 99)) + " lines.");
plugin.getLogger().info(Colors.Yellow + "To read the full changelog since " + lastVersion + ", go to https://github.com/TownyAdvanced/Towny/blob/master/resources/ChangeLog.txt#L" + ++startingIndex);
break;
}
String line = changeLog.get(i);
if (line.replaceAll(" ", "").replaceAll("\t", "").length() > 0) {
Bukkit.getLogger().info(line.trim().startsWith("-") ? line : Colors.Yellow + line);
++linesDisplayed;
}
}
} else {
plugin.getLogger().warning("Could not find starting index for the changelog.");
}
plugin.getLogger().info("------------------------------------");
} catch (IOException e) {
TownyMessaging.sendErrorMsg("Could not read ChangeLog.txt");
plugin.getLogger().warning("Could not read ChangeLog.txt");
}
}

Expand Down

0 comments on commit de181df

Please sign in to comment.