use of net.minecraft.world.storage.SaveHandler in project SpongeCommon by SpongePowered.
the class SpongeUser method save.
public void save() {
SaveHandler saveHandler = (SaveHandler) WorldManager.getWorldByDimensionId(0).get().getSaveHandler();
File dataFile = new File(saveHandler.playersDirectory, getUniqueId() + ".dat");
NBTTagCompound tag;
if (dataFile.isFile()) {
try {
tag = CompressedStreamTools.readCompressed(new FileInputStream(dataFile));
} catch (IOException ignored) {
// Nevermind
tag = new NBTTagCompound();
}
} else {
tag = new NBTTagCompound();
}
writeToNbt(tag);
try {
CompressedStreamTools.writeCompressed(tag, new FileOutputStream(dataFile));
dirtyUsers.remove(this);
} catch (IOException e) {
SpongeImpl.getLogger().warn("Failed to save user file [{}]!", dataFile, e);
}
}
use of net.minecraft.world.storage.SaveHandler in project SpongeCommon by SpongePowered.
the class UserDiscoverer method getAllProfiles.
static Collection<org.spongepowered.api.profile.GameProfile> getAllProfiles() {
Preconditions.checkState(Sponge.isServerAvailable(), "Server is not available!");
Set<org.spongepowered.api.profile.GameProfile> profiles = Sets.newHashSet();
// Add all cached profiles
profiles.addAll(userCache.asMap().values().stream().map(User::getProfile).collect(Collectors.toList()));
// Add all known profiles from the data files
SaveHandler saveHandler = (SaveHandler) WorldManager.getWorldByDimensionId(0).get().getSaveHandler();
String[] uuids = saveHandler.getAvailablePlayerDat();
for (String playerUuid : uuids) {
// before passing that back in getAvailablePlayerDat. It doesn't remove non ".dat" filenames from the list.
if (playerUuid.contains(".")) {
continue;
}
// At this point, we have a filename who has no extension. This doesn't mean it is actually a UUID. We trap the exception and ignore
// any filenames that fail the UUID check.
UUID uuid;
try {
uuid = UUID.fromString(playerUuid);
} catch (Exception ex) {
continue;
}
final GameProfile profile = SpongeImpl.getServer().getPlayerProfileCache().getProfileByUUID(uuid);
if (profile != null) {
profiles.add((org.spongepowered.api.profile.GameProfile) profile);
}
}
// Add all whitelisted users
final UserListWhitelist whiteList = SpongeImpl.getServer().getPlayerList().getWhitelistedPlayers();
profiles.addAll(whiteList.getValues().values().stream().map(entry -> (org.spongepowered.api.profile.GameProfile) entry.value).collect(Collectors.toList()));
// Add all banned users
final UserListBans banList = SpongeImpl.getServer().getPlayerList().getBannedPlayers();
profiles.addAll(banList.getValues().values().stream().filter(entry -> entry != null).map(entry -> (org.spongepowered.api.profile.GameProfile) entry.value).collect(Collectors.toList()));
return profiles;
}
use of net.minecraft.world.storage.SaveHandler in project ArsMagica2 by Mithion.
the class PowerNodeCache method getFileFromChunk.
private File getFileFromChunk(World world, ChunkCoordIntPair chunk, boolean createNew) {
File saveFolder = saveDirs.get(world.provider.dimensionId);
if (saveFolder == null) {
ISaveHandler handler = world.getSaveHandler();
if (handler instanceof SaveHandler) {
saveFolder = new File(((SaveHandler) handler).getWorldDirectory(), folder);
saveFolder.mkdirs();
saveFolder = new File(saveFolder, String.format("DIM%d", world.provider.dimensionId));
saveFolder.mkdirs();
saveDirs.put(world.provider.dimensionId, saveFolder);
} else {
return null;
}
}
int rX = (int) Math.floor(chunk.chunkXPos / 32);
int rZ = (int) Math.floor(chunk.chunkZPos / 32);
String fileName = String.format("%d_%d%s", rX, rZ, extension);
File file = saveFilesCached.get(fileName);
if (file != null)
return file;
file = new File(saveFolder, fileName);
if (!file.exists()) {
if (createNew) {
try {
file.createNewFile();
} catch (Throwable t) {
t.printStackTrace();
}
} else {
return null;
}
}
saveFilesCached.put(fileName, file);
return file;
}
use of net.minecraft.world.storage.SaveHandler in project MinecraftForge by MinecraftForge.
the class ForgeEventFactory method firePlayerLoadingEvent.
public static void firePlayerLoadingEvent(EntityPlayer player, IPlayerFileData playerFileData, String uuidString) {
SaveHandler sh = (SaveHandler) playerFileData;
File dir = ObfuscationReflectionHelper.getPrivateValue(SaveHandler.class, sh, "playersDirectory", "field_" + "75771_c");
MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, dir, uuidString));
}
use of net.minecraft.world.storage.SaveHandler in project SpongeCommon by SpongePowered.
the class UserDiscoverer method getPlayerDataFile.
private static File getPlayerDataFile(UUID uniqueId) {
// This may be called triggered by mods using FakePlayer during
// initial world gen (before the overworld is registered). Because of
// this, we need to check if the overworld is actually registered yet
Optional<WorldServer> worldServer = WorldManager.getWorldByDimensionId(0);
if (!worldServer.isPresent()) {
return null;
}
// Note: Uses the overworld's player data
SaveHandler saveHandler = (SaveHandler) worldServer.get().getSaveHandler();
File file = new File(saveHandler.playersDirectory, uniqueId.toString() + ".dat");
if (file.exists()) {
return file;
}
return null;
}
Aggregations