Skip to content

Commit

Permalink
Remove NameHistory from Library
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRazen committed Oct 31, 2022
1 parent f02ecd6 commit cc07bc2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 50 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ Get Value from UUID:
`MojangAPI::getValueFromUUID('8d0a41175a764b72a7dc67b555119fef');`
Result: ewogICJ0aW1lc3RhbXAiIDogMT...

Get All Names from UUID:
`MojangAPI::getAllNamesFromUUID('8d0a41175a764b72a7dc67b555119fef);`
Result: ["LordRazen"]

Check if Skinfile Exists:
http://textures.minecraft.net/texture/d5c6dc2bbf51c36cfc7714585a6a5683ef2b14d47d8ff714654a893f5da622
`MojangAPI::validateSkinFileExists('d5c6dc2bbf51c36cfc7714585a6a5683ef2b14d47d8ff714654a893f5da622');`
Expand All @@ -31,6 +27,11 @@ Get Skinfile from Mojang Skin Servers:
`MojangAPI::getSkinFile('d5c6dc2bbf51c36cfc7714585a6a5683ef2b14d47d8ff714654a893f5da622');`
Result: GdImage

## Former Features
Get All Names from UUID (deprecated since Mojang stopped the API support):
`MojangAPI::getAllNamesFromUUID('8d0a41175a764b72a7dc67b555119fef);`
Result: ["LordRazen"]

<br>
<hr>
www.minecraft-heads.com
Expand Down
59 changes: 31 additions & 28 deletions src/MojangAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,35 @@ public static function getSkinFile(String $url): mixed
return false;
}

/**
* Get all playernames from a UUID
*
* @param String $uuid (Trimmed)
* @return mixed false|array $playernames
*/
public static function getAllNamesFromUUID(String $uuid): mixed
{
$request = self::MOJANG_NAMES_FROM_UUID_PART1 . $uuid . self::MOJANG_NAMES_FROM_UUID_PART2;
$response = json_decode(@file_get_contents($request));

# No response, return false
if ($response == NULL)
return false;

# Return playernames
$playernames = array();
foreach ($response as $playername) {
if (empty($playername->changedToAt)) {
$playernames[0] = $playername->name;
} else {
# Cut of last three characters from timestamp. The timestamp is in Milliseconds, but seconds are needed
$playernames[substr($playername->changedToAt, 0, -3)] = $playername->name;
}
}

return $playernames;
}
// /**
// * Get all playernames from a UUID
// *
// * MOJANG STOPPED THIS API! DEPRECATED METHOD!
// *
// * @deprecated
// * @param String $uuid (Trimmed)
// * @return mixed false|array $playernames
// */
// public static function getAllNamesFromUUID(String $uuid): mixed
// {
// $request = self::MOJANG_NAMES_FROM_UUID_PART1 . $uuid . self::MOJANG_NAMES_FROM_UUID_PART2;
// $response = json_decode(@file_get_contents($request));

// # No response, return false
// if ($response == NULL)
// return false;

// # Return playernames
// $playernames = array();
// foreach ($response as $playername) {
// if (empty($playername->changedToAt)) {
// $playernames[0] = $playername->name;
// } else {
// # Cut of last three characters from timestamp. The timestamp is in Milliseconds, but seconds are needed
// $playernames[substr($playername->changedToAt, 0, -3)] = $playername->name;
// }
// }

// return $playernames;
// }
}
36 changes: 18 additions & 18 deletions tests/MojangApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,23 @@ public function dataSetSkinFiles()
];
}

/**
* Test getAllNamesFromUUID()
*
* @test
* @dataProvider dataSetNames
*/
public function testGetAllNamesFromUUID(String $uuid, String $names)
{
$result = MojangAPI::getAllNamesFromUUID($uuid);
$this->assertEquals(json_encode($result), $names);
}
// /**
// * Test getAllNamesFromUUID()
// *
// * @test
// * @dataProvider dataSetNames
// */
// public function testGetAllNamesFromUUID(String $uuid, String $names)
// {
// $result = MojangAPI::getAllNamesFromUUID($uuid);
// $this->assertEquals(json_encode($result), $names);
// }

public function dataSetNames()
{
return [
['8d0a41175a764b72a7dc67b555119fef', '["LordRazen"]'],
['dcd9538627ff49f793dabeb125058df2', '{"0":"BadLady1998","1512312932":"MissPrincess98","1586369437":"Missi98"}']
];
}
// public function dataSetNames()
// {
// return [
// ['8d0a41175a764b72a7dc67b555119fef', '["LordRazen"]'],
// ['dcd9538627ff49f793dabeb125058df2', '{"0":"BadLady1998","1512312932":"MissPrincess98","1586369437":"Missi98"}']
// ];
// }
}

0 comments on commit cc07bc2

Please sign in to comment.