Skip to content

Commit

Permalink
Improve documentation and code of example
Browse files Browse the repository at this point in the history
Signed-off-by: spnda <43609023+spnda@users.noreply.github.com>
spnda committed Jun 19, 2021
1 parent 6353bec commit 46e044b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -3,28 +3,28 @@ import 'dart:io';
import 'package:dart_minecraft/dart_minecraft.dart';

Future<int> main() async {
/// In this example we'll read content from a NBT File,
/// which in its root compound has a single NBT_String that
/// contains a UUID of a player, we'll get the skin texture from.
/// In this example we'll read content from a NBT File
/// which in its root compound has a single NbtString that
/// contains a UUID of a player we'll try and get the skin texture from.
final nbtFile = NbtFile.fromPath('./example/data.nbt');
try {
await nbtFile.readFile();
} on FileSystemException catch (e) {
print(e);
return -1;
} on NbtFileReadException {
print('Cannot read data.nbt');
print('Failed to read data.nbt');
}

/// If the file doesn't exist we'll replace the file with some example
/// data. This is how one would create nbt data using this package.
/// If the file doesn't exist we'll instead use some example data.
/// This shows how one would create nbt data using this package.
nbtFile.root ??= NbtCompound(
name: '',
children: [
NbtString(
name: 'uuid',
value: '069a79f444e94726a5befca90e38aaf5' // This is Notch's UUID.
)
name: 'uuid',
value: '069a79f444e94726a5befca90e38aaf5', // This is Notch's UUID.
),
],
);

@@ -36,10 +36,11 @@ Future<int> main() async {
if (nbtString == null) return -1;
final profile = await Mojang.getProfile(nbtString.value);
final skinUrl = profile.textures.getSkinUrl();
print(skinUrl); // URL to Notch's skin texture.
print("Notch's Skin URL: $skinUrl"); // URL to Notch's skin texture.

/// As we've now got the URL for the texture, we'll write the link to
/// it to our previously read nbt file and re-write it to the file.
nbtFile.root!.removeWhere((tag) => tag.name == 'skinUrl');
nbtFile.root!.add(NbtString(name: 'skinUrl', value: skinUrl));
await nbtFile.writeFile();
return 0;

0 comments on commit 46e044b

Please sign in to comment.