cn.nukkit.utils.DefaultPlayerDataSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
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);
}
}