minecraft-src/net/minecraft/server/ChainedJsonException.java
2025-07-04 01:41:11 +03:00

80 lines
2.1 KiB
Java

package net.minecraft.server;
import com.google.common.collect.Lists;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
public class ChainedJsonException extends IOException {
private final List<ChainedJsonException.Entry> entries = Lists.<ChainedJsonException.Entry>newArrayList();
private final String message;
public ChainedJsonException(String message) {
this.entries.add(new ChainedJsonException.Entry());
this.message = message;
}
public ChainedJsonException(String message, Throwable cause) {
super(cause);
this.entries.add(new ChainedJsonException.Entry());
this.message = message;
}
public void prependJsonKey(String key) {
((ChainedJsonException.Entry)this.entries.get(0)).addJsonKey(key);
}
public void setFilenameAndFlush(String filename) {
((ChainedJsonException.Entry)this.entries.get(0)).filename = filename;
this.entries.add(0, new ChainedJsonException.Entry());
}
public String getMessage() {
return "Invalid " + this.entries.get(this.entries.size() - 1) + ": " + this.message;
}
public static ChainedJsonException forException(Exception exception) {
if (exception instanceof ChainedJsonException) {
return (ChainedJsonException)exception;
} else {
String string = exception.getMessage();
if (exception instanceof FileNotFoundException) {
string = "File not found";
}
return new ChainedJsonException(string, exception);
}
}
public static class Entry {
@Nullable
String filename;
private final List<String> jsonKeys = Lists.<String>newArrayList();
Entry() {
}
void addJsonKey(String key) {
this.jsonKeys.add(0, key);
}
@Nullable
public String getFilename() {
return this.filename;
}
public String getJsonKeys() {
return StringUtils.join(this.jsonKeys, "->");
}
public String toString() {
if (this.filename != null) {
return this.jsonKeys.isEmpty() ? this.filename : this.filename + " " + this.getJsonKeys();
} else {
return this.jsonKeys.isEmpty() ? "(Unknown file)" : "(Unknown file) " + this.getJsonKeys();
}
}
}
}