本文整理汇总了Java中cn.nukkit.nbt.NBTIO.readCompressed方法的典型用法代码示例。如果您正苦于以下问题:Java NBTIO.readCompressed方法的具体用法?Java NBTIO.readCompressed怎么用?Java NBTIO.readCompressed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.nbt.NBTIO
的用法示例。
在下文中一共展示了NBTIO.readCompressed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BaseLevelProvider
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
public BaseLevelProvider(Level level, String path) throws IOException {
this.level = level;
this.path = path;
File file_path = new File(this.path);
if (!file_path.exists()) {
file_path.mkdirs();
}
CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN);
if (levelData.get("Data") instanceof CompoundTag) {
this.levelData = levelData.getCompound("Data");
} else {
throw new LevelException("Invalid level.dat");
}
if (!this.levelData.contains("generatorName")) {
this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase());
}
if (!this.levelData.contains("generatorOptions")) {
this.levelData.putString("generatorOptions", "");
}
}
示例2: getOfflinePlayerData
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
public CompoundTag getOfflinePlayerData(String name) {
name = name.toLowerCase();
String path = this.getDataPath() + "players/";
File file = new File(path + name + ".dat");
if (this.shouldSavePlayerData() && file.exists()) {
try {
return NBTIO.readCompressed(new FileInputStream(file));
} catch (Exception e) {
file.renameTo(new File(path + name + ".dat.bak"));
this.logger.notice(this.getLanguage().translateString("nukkit.data.playerCorrupted", name));
}
} else {
this.logger.notice(this.getLanguage().translateString("nukkit.data.playerNotFound", name));
}
Position spawn = this.getDefaultLevel().getSafeSpawn();
CompoundTag nbt = new CompoundTag()
.putLong("firstPlayed", System.currentTimeMillis() / 1000)
.putLong("lastPlayed", System.currentTimeMillis() / 1000)
.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("0", spawn.x))
.add(new DoubleTag("1", spawn.y))
.add(new DoubleTag("2", spawn.z)))
.putString("Level", this.getDefaultLevel().getName())
.putList(new ListTag<>("Inventory"))
.putCompound("Achievements", new CompoundTag())
.putInt("playerGameType", this.getGamemode())
.putList(new ListTag<DoubleTag>("Motion")
.add(new DoubleTag("0", 0))
.add(new DoubleTag("1", 0))
.add(new DoubleTag("2", 0)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("0", 0))
.add(new FloatTag("1", 0)))
.putFloat("FallDistance", 0)
.putShort("Fire", 0)
.putShort("Air", 300)
.putBoolean("OnGround", true)
.putBoolean("Invulnerable", false)
.putString("NameTag", name);
this.saveOfflinePlayerData(name, nbt);
return nbt;
}
示例3: execute
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length == 0) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
String value = args[0];
String reason = "";
for (int i = 1; i < args.length; i++) {
reason += args[i] + " ";
}
if (reason.length() > 0) {
reason = reason.substring(0, reason.length() - 1);
}
if (Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", value)) {
this.processIPBan(value, sender, reason);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success", value));
} else {
Player player = sender.getServer().getPlayer(value);
if (player != null) {
this.processIPBan(player.getAddress(), sender, reason);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success.players", new String[]{player.getAddress(), player.getName()}));
} else {
String name = value.toLowerCase();
String path = sender.getServer().getDataPath() + "players/";
File file = new File(path + name + ".dat");
CompoundTag nbt = null;
if (file.exists()) {
try {
nbt = NBTIO.readCompressed(new FileInputStream(file));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (nbt != null && nbt.contains("lastIP") && Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", (value = nbt.getString("lastIP")))) {
this.processIPBan(value, sender, reason);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success", value));
} else {
sender.sendMessage(new TranslationContainer("commands.banip.invalid"));
return false;
}
}
}
return true;
}
示例4: getOfflinePlayerData
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
public CompoundTag getOfflinePlayerData(String name) {
name = name.toLowerCase();
String path = this.getDataPath() + "players/";
File file = new File(FastAppender.get(path, name, ".dat"));
if (this.shouldSavePlayerData() && file.exists()) {
try {
return NBTIO.readCompressed(new FileInputStream(file));
} catch (Exception e) {
file.renameTo(new File(FastAppender.get(path, name, ".dat.bak")));
this.logger.notice(this.getLanguage().translateString("nukkit.data.playerCorrupted", name));
}
} else {
this.logger.notice(this.getLanguage().translateString("nukkit.data.playerNotFound", name));
}
Position spawn = this.getDefaultLevel().getSafeSpawn();
CompoundTag nbt = new CompoundTag()
.putLong("firstPlayed", System.currentTimeMillis() / 1000)
.putLong("lastPlayed", System.currentTimeMillis() / 1000)
.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("0", spawn.x))
.add(new DoubleTag("1", spawn.y))
.add(new DoubleTag("2", spawn.z)))
.putString("Level", this.getDefaultLevel().getName())
.putList(new ListTag<>("Inventory"))
.putCompound("Achievements", new CompoundTag())
.putInt("playerGameType", this.getDefaultGamemode())
.putList(new ListTag<DoubleTag>("Motion")
.add(new DoubleTag("0", 0))
.add(new DoubleTag("1", 0))
.add(new DoubleTag("2", 0)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("0", 0))
.add(new FloatTag("1", 0)))
.putFloat("FallDistance", 0)
.putShort("Fire", 0)
.putShort("Air", 300)
.putBoolean("OnGround", true)
.putBoolean("Invulnerable", false)
.putString("NameTag", name);
this.saveOfflinePlayerData(name, nbt);
return nbt;
}