cn.nukkit.utils.DefaultPlayerDataSerializer Maven / Gradle / Ivy
package cn.nukkit.utils;
import cn.nukkit.Server;
import cn.nukkit.api.Since;
import com.google.common.base.Preconditions;
import java.io.*;
import java.util.Optional;
import java.util.UUID;
public class DefaultPlayerDataSerializer implements PlayerDataSerializer {
private String dataPath;
@Since("1.4.0.0-PN")
public DefaultPlayerDataSerializer(Server server) {
this(server.getDataPath());
}
@Since("1.4.0.0-PN")
public DefaultPlayerDataSerializer(String dataPath) {
this.dataPath = dataPath;
}
@Override
public Optional read(String name, UUID uuid) throws IOException {
String path = dataPath + "players/" + name + ".dat";
File file = new File(path);
if (!file.exists()) {
return Optional.empty();
}
return Optional.of(new FileInputStream(file));
}
@Override
public OutputStream write(String name, UUID uuid) throws IOException {
Preconditions.checkNotNull(name, "name");
String path = dataPath + "players/" + name + ".dat";
File file = new File(path);
return new FileOutputStream(file);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy