Skip to content

Commit

Permalink
Prevent premium player from being deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
tnqzh123 committed Jan 27, 2024
1 parent 7193246 commit a71c6fd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use App\Services\Hook;
use Blessing\Filter;
use Blessing\Rejection;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -44,6 +45,11 @@
'LittleSkin\PremiumVerification\Listeners\OnAuthenticated@handle'
);

$events->listen(
'player.delete.attempt',
'LittleSkin\PremiumVerification\Listeners\OnPlayerDeleteAttempt@handle'
);

$events->listen(
'user.deleting',
'LittleSkin\PremiumVerification\Listeners\OnUserDeleting@handle'
Expand Down
1 change: 1 addition & 0 deletions lang/en/premium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ verified-by-other: 这个正版账号已经被其他 LittleSkin 账号绑定过
already-verified: 你已经绑定过正版账号了
not-verified: 你还没有绑定过正版账号
deleted: (已删除)
player-cannot-be-deleted: 正版绑定角色不允许删除

premium-uuid: 正版角色 UUID
premium-uuid-tip: 不是绑定角色的 UUID
Expand Down
1 change: 1 addition & 0 deletions lang/zh_CN/premium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ verified-by-other: 这个正版账号已经被其他 LittleSkin 账号绑定过
already-verified: 你已经绑定过正版账号了
not-verified: 你还没有绑定过正版账号
deleted: (已删除)
player-cannot-be-deleted: 正版绑定角色不允许删除

premium-uuid: 正版角色 UUID
premium-uuid-tip: 不是绑定角色的 UUID
Expand Down
26 changes: 26 additions & 0 deletions src/Listeners/OnPlayerDeleteAttempt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace LittleSkin\PremiumVerification\Listeners;

use Blessing\Filter;
use Blessing\Rejection;
use LittleSkin\PremiumVerification\Models\Premium;

class OnPlayerDeleteAttempt {
/** @var Filter */
protected $filter;

public function __construct(Filter $filter)
{
$this->filter = $filter;
}

public function handle() {
$this->filter->add('can_delete_player', function($can, $player) {
if(Premium::where('pid', $player->pid)->count()) {
return new Rejection(trans("LittleSkin\PremiumVerification::premium.player-cannot-be-deleted"));
}
return $can;
});
}
}

0 comments on commit a71c6fd

Please sign in to comment.