GitHub 저장소spnda/dart_minecraft

dart_minecraft

Minecraft 및 Mojang Web-API, 인증 및 NBT 파일용 Dart 라이브러리.

dart_minecraft 프로젝트 이미지
스타
23
포크
7
최근 푸시(UTC)
2024. 5. 22.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

dart_minecraft

Pub Package GitHub Issues GitHub Stars GitHub License

A simple Dart library for interfacing with the Mojang and Minecraft APIs. It also includes NBT read/write functionality and functions to ping Minecraft: Java Edition servers.

You can simply import the library like this:

import 'package:dart_minecraft/dart_minecraft.dart';

Examples

Below are some basic examples of the features included in this library. A better and more extensive example can be found here. However you should always keep in mind that there is a rate limit on all API, set at 600 requests per 10 minutes. You are expected to cache the results and this is not done by the library itself.

Authenticating with Mojang API

dart_minecraft offers functionality to authenticate with the Mojang API called Yggdrasil.

void main() async {
    // This authenticates, invalidates older tokens, and gets a new access
    // and client token. Be sure to store them, but keep them safe.
    MojangAccount account = authenticate("username", "password");
}
Skin/Cape of a player

Get the skin and/or cape texture URL of a player. This just requires the player's UUID or username.

void main() async {
    // PlayerUUID is a Pair<String, String>
    PlayerUuid player = await getUuid('<your username>');
    Profile profile = await getProfile(player.second);
    String url = profile.textures.getSkinUrl();
}
Reading NBT data

Read NBT data from a local file. This supports the full NBT specification, however support for SNBT is not implemented yet. A full list of tags/types usable in this context can be found here.

void main() async {
    // You can create a NbtFile object from a File object or
    // from a String path.
    final nbtReader = NbtReader.fromFile('yourfile.nbt');
    await nbtReader.read();
    NbtCompound rootNode = nbtReader.root;
    // You can now read information from your [rootNode].
    // for example, rootNode[0] will return the first child,
    // if present.
    print(rootNode.first);
    print(rootNode.getChildrenByTag(NbtTagType.TAG_STRING));
}
Pinging a server

Pings the Minecraft: Java Edition (1.6+) server at 'mc.hypixel.net'. You can use any DNS or IP Address to ping them. The server will provide basic information, as the player count, ping and MOTD.

void main() async {
	/// Pinging a server and getting its basic information is 
	/// as easy as that.
	final server = await ping('mc.hypixel.net');
	if (server == null || server.response == null) return;
	print('Latency: ${server.ping}');
	final players = ping.response!.players;
	print('${players.online} / ${players.max}'); // e.g. 5 / 20
}

License

The MIT License, see LICENSE.

Sean Apeler GitHub avatar
GitHub 작성자

Sean Apeler ↗

Studying Computer Engineering

RWTH Aachen UniversityAachen, Germany
언어Dart

분류

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 6 개

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗