Skip to content

Commit

Permalink
unlink player
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Jun 3, 2024
1 parent 399d4c5 commit 0d4b0d9
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 54 deletions.
30 changes: 30 additions & 0 deletions app/Http/Controllers/Admin/PlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Jobs\AccountUnlinkAfterSuccessCommandJob;
use App\Models\MinecraftPlayerSession;
use App\Models\Player;
use DB;
use Illuminate\Http\Request;

class PlayerController extends Controller
{
Expand All @@ -22,4 +24,32 @@ public function destroy(Player $player)
return redirect()->back()
->with(['toast' => ['type' => 'success', 'title' => __('Player Deleted!'), 'body' => __('All intel data related to the player is deleted.')]]);
}

public function unlink(Player $player, Request $request)
{
$this->authorize('unlink', $player);

$attachedUser = $player->users()->first();
if (! $attachedUser) {
return redirect()->back()
->with(['toast' => ['type' => 'danger', 'title' => __('Not Linked!'), 'body' => __('Player is not linked to any user.')]]);
}

// Unlink the player
$player->users()->detach($attachedUser->id);

// If MARK_USER_VERIFYED_ON_ACCOUNT_LINK is enabled then mark user as unverified when he unlink all players.
$linkedPlayersExist = $attachedUser->players()->exists();
if (config('minetrax.mark_user_verified_on_account_link') && $attachedUser->verified_at && ! $linkedPlayersExist) {
$attachedUser->verified_at = null;
$attachedUser->save();
}

// Dispatch unlink after success commands
AccountUnlinkAfterSuccessCommandJob::dispatch($player, $attachedUser->id);

// Return redirect back with flash
return redirect()->back()
->with(['toast' => ['type' => 'success', 'title' => __('Played unlinked successfully!'), 'body' => __('Player has been unlinked from that account.'), 'milliseconds' => 10000]]);
}
}
5 changes: 5 additions & 0 deletions app/Policies/PlayerPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ public function destroy(User $user, Player $player)
{
return $user->can('delete players');
}

public function unlink(User $user, Player $player)
{
return $user->can('unlink any_players');
}
}
3 changes: 3 additions & 0 deletions database/seeders/PermissionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,8 @@ public function run()
Permission::findOrCreate('create command_queues');
Permission::findOrCreate('read command_queues');
Permission::findOrCreate('delete command_queues');

Permission::findOrCreate('link any_players');
Permission::findOrCreate('unlink any_players');
}
}
2 changes: 1 addition & 1 deletion resources/default/js/Pages/Admin/User/EditUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<x-checkbox
id="show_yob"
v-model="form.show_yob"
:label="__('Show Your of Birth')"
:label="__('Show Year of Birth')"
:help="__('Show Year of Birth in your public profile.')"
name="show_yob"
:error="form.errors.show_yob"
Expand Down
118 changes: 66 additions & 52 deletions resources/default/js/Pages/Player/ShowPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@
{{ __("Claimed By") }}
</p>
</div>
<p>
<p class="flex items-start space-x-2">
<inertia-link
v-if="player.owner"
class="font-bold text-light-blue-400 hover:text-light-blue-600"
Expand All @@ -659,6 +659,23 @@
v-else
class="italic text-gray-500"
>{{ __("None") }}</span>


<InertiaLink
v-if="can('unlink any_players') && player.owner"
v-confirm="{
message:
'Are you sure you want to unlink this player from current user?',
}"
v-tippy
as="button"
method="DELETE"
:href="route('admin.player.unlink', player.uuid)"
class="inline-flex items-center justify-center text-red-600 hover:text-red-900 focus:outline-none"
:title="__('Unlink Player')"
>
<LockOpenIcon class="inline-block w-5 h-5" />
</InertiaLink>
</p>
</div>
<div class="flex justify-between">
Expand Down Expand Up @@ -769,64 +786,61 @@
</app-layout>
</template>

<script>
<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
import AppLayout from '@/Layouts/AppLayout.vue';
import Icon from '@/Components/Icon.vue';
import * as skinview3d from 'skinview3d';
import {useHelpers} from '@/Composables/useHelpers';
import { useHelpers } from '@/Composables/useHelpers';
import millify from 'millify';
import PlayerSubMenu from '@/Shared/PlayerSubMenu.vue';
import { LockOpenIcon } from '@heroicons/vue/24/outline';
import { useTranslations } from '@/Composables/useTranslations';
import { useAuthorizable } from '@/Composables/useAuthorizable';
const { __ } = useTranslations();
const { can } = useAuthorizable();
export default {
const props = defineProps({
player: Object,
canShowPlayerIntel: Boolean,
canChangePlayerSkin: Boolean,
});
components: {
PlayerSubMenu,
Icon,
AppLayout,
},
props: {
player: Object,
canShowPlayerIntel: Boolean,
canChangePlayerSkin: Boolean,
},
setup() {
const {secondsToHMS, formatTimeAgoToNow, formatToDayDateString} = useHelpers();
return {secondsToHMS, formatTimeAgoToNow, formatToDayDateString, millify};
},
data() {
return {
playerAnimationEnabled: true,
skinViewer: null,
};
},
mounted() {
this.skinViewer = new skinview3d.SkinViewer({
canvas: document.getElementById('skin_container'),
width: 300,
height: 500,
skin: route('player.skin.get', {uuid: this.player.uuid, username: this.player.username, textureid: this.player.skin_texture_id}),
});
this.skinViewer.autoRotate = true;
this.skinViewer.animation = new skinview3d.WalkingAnimation();
this.skinViewer.animation.speed = 0.1;
this.skinViewer.autoRotateSpeed = 0.5;
},
unmounted() {
this.skinViewer.dispose();
},
const { secondsToHMS, formatTimeAgoToNow, formatToDayDateString } = useHelpers();
methods: {
toggle3dPlayerAnimation: function () {
if (this.playerAnimationEnabled) {
// Disable Animation
this.skinViewer.animation.paused = true;
this.playerAnimationEnabled = false;
} else {
// Enable Animation
this.skinViewer.animation.paused = false;
this.playerAnimationEnabled = true;
}
},
},
const playerAnimationEnabled = ref(true);
let skinViewer = null;
onMounted(() => {
skinViewer = new skinview3d.SkinViewer({
canvas: document.getElementById('skin_container'),
width: 300,
height: 500,
skin: route('player.skin.get', { uuid: props.player.uuid, username: props.player.username, textureid: props.player.skin_texture_id }),
});
skinViewer.autoRotate = true;
skinViewer.animation = new skinview3d.WalkingAnimation();
skinViewer.animation.speed = 0.1;
skinViewer.autoRotateSpeed = 0.5;
});
onUnmounted(() => {
if (skinViewer) {
skinViewer.dispose();
}
});
const toggle3dPlayerAnimation = () => {
if (playerAnimationEnabled.value) {
// Disable Animation
skinViewer.animation.paused = true;
playerAnimationEnabled.value = false;
} else {
// Enable Animation
skinViewer.animation.paused = false;
playerAnimationEnabled.value = true;
}
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<x-checkbox
id="show_yob"
v-model="form.show_yob"
:label="__('Show Your of Birth')"
:label="__('Show Year of Birth')"
:help="__('Show Year of Birth in your public profile.')"
name="show_yob"
:error="form.errors.show_yob"
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
Route::get('intel/player/list', [\App\Http\Controllers\Admin\PlayerIntelController::class, 'playersList'])->name('intel.player.list');

Route::delete('intel/player/{player:uuid}/delete', [\App\Http\Controllers\Admin\PlayerController::class, 'destroy'])->name('intel.player.delete');
Route::delete('player/{player:uuid}/unlink', [\App\Http\Controllers\Admin\PlayerController::class, 'unlink'])->name('player.unlink');

Route::get('rank', [\App\Http\Controllers\Admin\RankController::class, 'index'])->name('rank.index');
Route::get('rank/create', [\App\Http\Controllers\Admin\RankController::class, 'create'])->name('rank.create');
Expand Down

0 comments on commit 0d4b0d9

Please sign in to comment.