Move version and console history to .paper dir (#14104)

This commit is contained in:
Nassim Jahnke 2026-07-26 14:51:17 +02:00 committed by GitHub
parent 2d76c9c1d0
commit 57d665efcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 63 additions and 4 deletions

View file

@ -3,13 +3,13 @@ package com.destroystokyo.paper;
import com.google.common.base.MoreObjects;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import io.papermc.paper.util.PaperCacheDir;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.logging.Level;
@ -29,7 +29,7 @@ public enum VersionHistoryManager {
private VersionData currentData = null;
VersionHistoryManager() {
final Path path = Paths.get("version_history.json");
final Path path = PaperCacheDir.moveFromServerRootAndGet("version_history.json", "version_history.json");
if (Files.exists(path)) {
// Basic file sanity checks

View file

@ -3,6 +3,7 @@ package com.destroystokyo.paper.console;
import io.papermc.paper.configuration.GlobalConfiguration;
import io.papermc.paper.console.BrigadierCompletionMatcher;
import io.papermc.paper.console.BrigadierConsoleParser;
import io.papermc.paper.util.PaperCacheDir;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecrell.terminalconsole.SimpleTerminalConsole;
import org.bukkit.craftbukkit.command.ConsoleCommandCompleter;
@ -21,7 +22,7 @@ public final class PaperConsole extends SimpleTerminalConsole {
protected LineReader buildReader(LineReaderBuilder builder) {
builder
.appName("Paper")
.variable(LineReader.HISTORY_FILE, java.nio.file.Paths.get(".console_history"))
.variable(LineReader.HISTORY_FILE, PaperCacheDir.moveFromServerRootAndGet(".console_history", "console_history"))
.completer(new ConsoleCommandCompleter(this.server))
.option(LineReader.Option.COMPLETE_IN_WORD, true);
if (io.papermc.paper.configuration.GlobalConfiguration.get().console.enableBrigadierHighlighting) {

View file

@ -0,0 +1,57 @@
package io.papermc.paper.util;
import com.mojang.logging.LogUtils;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.slf4j.Logger;
public final class PaperCacheDir {
private static final Path PATH = Path.of(".paper");
private static final Logger LOGGER = LogUtils.getLogger();
public static Path get() {
if (!Files.exists(PATH)) {
try {
Files.createDirectories(PATH);
} catch (final IOException e) {
throw new RuntimeException("Error creating .paper cache dir", e);
}
}
if (!Files.isDirectory(PATH)) {
throw new RuntimeException(".paper cache dir is not a directory");
}
return PATH;
}
public static Path get(final String child) {
return get().resolve(child);
}
public static Path moveFromServerRootAndGet(final String child, final String newName) {
// Keep this for individual use until a more unified migration place is made for larger config migrations
final Path path = Path.of(child);
final Path target = get(newName);
if (!Files.isRegularFile(path)) {
return target;
}
if (Files.exists(target)) {
// Delete the one in the server root
try {
Files.deleteIfExists(path);
} catch (final IOException e) {
LOGGER.error("Error deleting file: {}", child, e);
}
} else {
// Move into .paper
try {
Files.move(path, target);
} catch (final IOException e) {
LOGGER.error("Error moving file: {}", child, e);
}
}
return target;
}
}

View file

@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.map;
import com.google.common.base.Preconditions;
import io.papermc.paper.util.PaperCacheDir;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
@ -21,7 +22,7 @@ import org.bukkit.map.MapPalette;
public class CraftMapColorCache implements MapPalette.MapColorCache {
private static final String MD5_CACHE_HASH = "E88EDD068D12D39934B40E8B6B124C83"; // 248 colors
private static final File CACHE_FILE = new File("map-color-cache.dat");
private static final File CACHE_FILE = PaperCacheDir.get("map-color-cache.dat").toFile();
private byte[] cache;
private final Logger logger;
private boolean cached = false;