本文整理汇总了Java中org.spongepowered.api.data.DataContainer.getView方法的典型用法代码示例。如果您正苦于以下问题:Java DataContainer.getView方法的具体用法?Java DataContainer.getView怎么用?Java DataContainer.getView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.data.DataContainer
的用法示例。
在下文中一共展示了DataContainer.getView方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import org.spongepowered.api.data.DataContainer; //导入方法依赖的package包/类
public static void save(Path dataFolder, AbstractUser player) throws IOException {
final String fileName = player.getUniqueId().toString() + ".dat";
final DataContainer dataContainer = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
final ObjectStore<AbstractUser> objectStore = ObjectStoreRegistry.get().get(AbstractUser.class).get();
objectStore.serialize(player, dataContainer);
final Optional<DataView> optSpongeData = dataContainer.getView(DataQueries.EXTENDED_SPONGE_DATA);
dataContainer.remove(DataQueries.EXTENDED_SPONGE_DATA);
Path dataFolder0 = dataFolder.resolve(PLAYER_DATA_FOLDER);
if (!Files.exists(dataFolder0)) {
Files.createDirectories(dataFolder0);
}
Path dataFile = dataFolder0.resolve(fileName);
NbtStreamUtils.write(dataContainer, Files.newOutputStream(dataFile), true);
dataFolder0 = dataFolder.resolve(SPONGE_PLAYER_DATA_FOLDER);
if (!Files.exists(dataFolder0)) {
Files.createDirectories(dataFolder0);
}
dataFile = dataFolder0.resolve(fileName);
if (optSpongeData.isPresent()) {
final DataView spongeData = optSpongeData.get();
spongeData.set(NAME, player.getName());
NbtStreamUtils.write(spongeData, Files.newOutputStream(dataFile), true);
} else {
Files.deleteIfExists(dataFile);
}
final Path statisticsFile = dataFolder.resolve(STATISTICS_FOLDER).resolve(player.getUniqueId().toString() + ".json");
player.getStatisticMap().save(statisticsFile);
}