All Projects → innocenzi → MojangSharp

innocenzi / MojangSharp

Licence: other
A C# wrapper library for Mojang API (no longer actively maintained)

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to MojangSharp

buckshot
A fast and capable Minecraft name sniper.
Stars: ✭ 21 (-44.74%)
Mutual labels:  asynchronous, mojang, mojang-authentication, mojang-api
Hubot Minecraft Skin
Hubot's very own Minecraft skin
Stars: ✭ 85 (+123.68%)
Mutual labels:  minecraft, skin
Mccustomskinloader
Custom Skin Loader for Minecraft
Stars: ✭ 261 (+586.84%)
Mutual labels:  minecraft, skin
SpotifyWebApi
A .net core wrapper for the Spotify Web API
Stars: ✭ 19 (-50%)
Mutual labels:  wrapper, nuget
Pokeapi Js Wrapper
PokeAPI browser wrapper, fully async with built-in cache
Stars: ✭ 129 (+239.47%)
Mutual labels:  wrapper, asynchronous
Realtaiizor
C# WinForm UI/UX Component Library
Stars: ✭ 109 (+186.84%)
Mutual labels:  skin, nuget
Mcsniperpy
Minecraft name sniper written in python.
Stars: ✭ 98 (+157.89%)
Mutual labels:  minecraft, asynchronous
Simplenetnlp
.NET NLP library
Stars: ✭ 38 (+0%)
Mutual labels:  wrapper, nuget
net-Socket
A minimalist wrapper around System.Net.Sockets.Socket.
Stars: ✭ 21 (-44.74%)
Mutual labels:  wrapper, nuget
CallofDuty.py
Asynchronous, object-oriented Python wrapper for the Call of Duty API.
Stars: ✭ 86 (+126.32%)
Mutual labels:  wrapper, asynchronous
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (+218.42%)
Mutual labels:  wrapper, nuget
Stockpile
Smart caching server for the Mojang API
Stars: ✭ 12 (-68.42%)
Mutual labels:  mojang-authentication, mojang-api
Binancedotnet
Official C# Wrapper for the Binance exchange API, with REST and WebSocket endpoints
Stars: ✭ 102 (+168.42%)
Mutual labels:  wrapper, nuget
MineRender
Quick, Easy, Interactive 3D/2D Renders of Minecraft
Stars: ✭ 76 (+100%)
Mutual labels:  minecraft, skin
Binance.api.csharp.client
C#.NET client for Binance Exchange API.
Stars: ✭ 98 (+157.89%)
Mutual labels:  wrapper, nuget
Minecraft Avatar
PHP script (using GD) to generate avatar or skin from a Minecraft username
Stars: ✭ 104 (+173.68%)
Mutual labels:  minecraft, skin
Framework
Machine learning, computer vision, statistics and general scientific computing for .NET
Stars: ✭ 4,177 (+10892.11%)
Mutual labels:  statistics, nuget
Opencvsharp
OpenCV wrapper for .NET
Stars: ✭ 3,598 (+9368.42%)
Mutual labels:  wrapper, nuget
mojang
A wrapper for the Mojang API and Minecraft website
Stars: ✭ 19 (-50%)
Mutual labels:  mojang, mojang-api
Shift
Light-weight EventKit wrapper.
Stars: ✭ 31 (-18.42%)
Mutual labels:  wrapper, asynchronous

MojangSharp

MojangSharp is a C# wrapper for the Mojang API and Mojang Authentication API.

Features

  • Asynchronous API
  • All error and response types handled
  • Really easy to use

Getting started

GitHub release GitHub issues   NuGet NuGet downloads

Installation

You will need to install MojangSharp by downloading it or installing it from NuGet with MS> Install-Package Hawezo.MojangSharp.

Usage

MojangSharp contains a Endpoints namespace which contains all of the possible actions. See the few examples below to understand their usage:

ApiStatus

First, get Response object corresponding to the Endpoint you are using. In the case of ApiStatus, the Response object is ApiStatusResponse. Then, instantiate the Endpoint object and call its method asynchronous PerformRequest().

ApiStatusResponse status = await new ApiStatus().PerformRequest();

If the request is a success, the boolean value of status.IsSuccess would be set to true. Otherwise, the Error property will indicates where is the issue coming from.

Assuming the request is a success, you can access each property of status to get the responses you needed:

Console.WriteLine($"Mojang: {status.Mojang}");
Console.WriteLine($"Minecraft: {status.Minecraft}");
Console.WriteLine($"Skins: {status.Skins}");
Console.WriteLine($"Sessions: {status.Sessions}");
//...

Authentication

Authentication's request type is the same as the other. You will need to instanciate a Credentials object containing the username and the password of the player you want to authenticate. Then, you will be able to perform the request and get an access token.

AuthenticateResponse auth = await new Authenticate(new Credentials() { Username = "<mail>/<username>", Password = "<password>" }).PerformRequest();
if (auth.IsSuccess) {
  Console.WriteLine($"AccessToken: {auth.AccessToken}");
  Console.WriteLine($"ClientToken: {auth.ClientToken}");
} else { // Handle your error }

Note that ClientToken is an auto-generated token coming from the library. The first time it is used, you can decide to store it somewhere and thus be able to user the Validate, Invalidate and the other endpoints of the Authentication API. You can check after an authentication request if the Client Token is the same as the one stored in Requester.ClientToken. If not, there is probably an issue with your authentication structure.

Location

Some endpoints use Bearer Authentication to authenticate a player thanks to its access token, which is retrieved thanks to the Authentication endpoint.

Sometimes, Mojang rejects a requests because it assumes the request is not secured due to its location. In order to determine if Mojang will accept these kind of requests, you will need to use the SecureIP endpoint.

Response secured = new SecureIP(auth.AccessToken).PerformRequestAsync().Result;
if (secured.IsSuccess)
    // Mojang will likely accept requests coming from this IP :)
else
    // Mojang will reject further requests.

Skins

Warning - Please perform your own tests for all skin-related endpoints, this feature has not been tested (but the requests work so it is likely working).

You can change or reset a skin with MojangSharp. To change a skin, you can either call UploadSkin endpoint to upload a skin to the Mojang's servers, or call ChangeSkin with an URL to the skin you want to change to.

Response skinUpload = await new UploadSkin(auth.AccessToken, auth.SelectedProfile.Value, new FileInfo(@"<path>")).PerformRequest();
if (skinUpload.IsSuccess) {
  Console.WriteLine("Successfully changed skin.")
} else { // Handle your errors }

Blocked servers

Mojang has a list of actually blocked addresses, which are SHA1-hashed. Some of them has been cracked by the community and are listed in MojangSharp.

BlockedServersResponse servers = await new BlockedServers().PerformRequest();
if (servers.IsSuccess) {
    Console.WriteLine($"{servers.BlockedServers.Count} blocked servers");
    Console.WriteLine($"{servers.BlockedServers.FindAll(x => x.Cracked).Count} cracked");
}
else { // You know what }

Statistics

Mojang offers an endpoint to get its statistics. Although there is not a lot of interest, it can somehow be useful. You can combine up to 4 statistics in the Statistics constructor, in which case the resulting numbers will be added to each other.

StatisticsResponse stats = await new Statistics(Item.MinecraftAccountsSold).PerformRequest();
if (stats.IsSuccess) {
    Console.WriteLine($"Total Minecraft accounts sold: {stats.Total}");
    Console.WriteLine($"Last 24h: {stats.Last24h}");
    Console.WriteLine($"Average sell/s: {stats.SaleVelocity}");
} else { // Handle your errors }

Dependencies

MojangSharp uses Newtonsoft's JSON to parse Mojang's API responses.

To-do

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].