Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the amount of changelog lines printed to 100. #5352

Merged
merged 4 commits into from
Oct 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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