This commit is contained in:
Pig Fang 2019-12-30 23:51:12 +08:00
parent 611f6c8cee
commit e97d2743fb
3 changed files with 1 additions and 28 deletions

View File

@ -137,7 +137,7 @@ class TextureController extends Controller
$player = Player::where('name', $name)->first();
abort_unless($player, 404);
$hash = $player->getTexture('skin');
$hash = optional($player->skin)->hash;
if (Storage::disk('textures')->has($hash)) {
$png = Minecraft::generateAvatarFromSkin(
Storage::disk('textures')->read($hash),

View File

@ -73,20 +73,4 @@ class Player extends Model
return json_encode($profile, $options | JSON_UNESCAPED_UNICODE);
}
/**
* Get specific texture of player.
*
* @param string $type "skin" or "cape"
*
* @return string the sha256 hash of texture file
*/
public function getTexture($type)
{
if (in_array($type, self::$types)) {
return Arr::get(Texture::find($this["tid_$type"]), 'hash');
}
return false;
}
}

View File

@ -10,17 +10,6 @@ class PlayerTest extends TestCase
{
use DatabaseTransactions;
public function testGetTexture()
{
$skin = factory(Texture::class)->create();
$player = factory(Player::class)->create(['tid_skin' => $skin->tid]);
$player = Player::find($player->pid);
$this->assertEquals($skin->hash, $player->getTexture('skin'));
$this->assertFalse($player->getTexture('invalid_type'));
}
public function testGetModelAttribute()
{
$player = factory(Player::class)->create();