CommandHistory.java
net.minecraft.client.CommandHistory
信息
- 全限定名:net.minecraft.client.CommandHistory
- 类型:public class
- 包:net.minecraft.client
- 源码路径:src/main/java/net/minecraft/client/CommandHistory.java
- 起始行号:L17
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
MAX_PERSISTED_COMMAND_HISTORY- 类型:
int - 修饰符:
private static final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
PERSISTED_COMMANDS_FILE_NAME- 类型:
String - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
commandsPath- 类型:
Path - 修饰符:
private final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
lastCommands- 类型:
ArrayListDeque<String> - 修饰符:
private final - 源码定位:
L22 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public CommandHistory(Path gameFolder) @ L24
- 构造器名:CommandHistory
- 源码定位:L24
- 修饰符:public
参数:
- gameFolder: Path
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void addCommand(String command) @ L35
- 方法名:addCommand
- 源码定位:L35
- 返回类型:void
- 修饰符:public
参数:
- command: String
说明:
TODO
private void save() @ L46
- 方法名:save
- 源码定位:L46
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
public Collection<String> history() @ L57
- 方法名:history
- 源码定位:L57
- 返回类型:Collection
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class CommandHistory {
private static final Logger LOGGER = LogUtils.getLogger();
private static final int MAX_PERSISTED_COMMAND_HISTORY = 50;
private static final String PERSISTED_COMMANDS_FILE_NAME = "command_history.txt";
private final Path commandsPath;
private final ArrayListDeque<String> lastCommands = new ArrayListDeque<>(50);
public CommandHistory(Path gameFolder) {
this.commandsPath = gameFolder.resolve("command_history.txt");
if (Files.exists(this.commandsPath)) {
try (BufferedReader reader = Files.newBufferedReader(this.commandsPath, StandardCharsets.UTF_8)) {
this.lastCommands.addAll(reader.lines().toList());
} catch (Exception var7) {
LOGGER.error("Failed to read {}, command history will be missing", "command_history.txt", var7);
}
}
}
public void addCommand(String command) {
if (!command.equals(this.lastCommands.peekLast())) {
if (this.lastCommands.size() >= 50) {
this.lastCommands.removeFirst();
}
this.lastCommands.addLast(command);
this.save();
}
}
private void save() {
try (BufferedWriter writer = Files.newBufferedWriter(this.commandsPath, StandardCharsets.UTF_8)) {
for (String command : this.lastCommands) {
writer.write(command);
writer.newLine();
}
} catch (IOException var6) {
LOGGER.error("Failed to write {}, command history will be missing", "command_history.txt", var6);
}
}
public Collection<String> history() {
return this.lastCommands;
}
}引用的其他类
- ArrayListDeque
- 引用位置:
字段
- 引用位置: