2024-04-16 23:16:34 +01:00
|
|
|
/* eslint-disable @next/next/no-img-element */
|
2024-04-16 21:18:08 +01:00
|
|
|
import { Card } from "@/app/components/card";
|
2024-04-17 17:21:15 +01:00
|
|
|
import { ErrorCard } from "@/app/components/error-card";
|
2024-04-16 19:12:26 +01:00
|
|
|
import { LookupPlayer } from "@/app/components/player/lookup-player";
|
2024-04-17 18:26:53 +01:00
|
|
|
import { Separator } from "@/app/components/ui/separator";
|
2024-04-17 18:08:13 +01:00
|
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/app/components/ui/tooltip";
|
2024-04-16 18:14:15 +01:00
|
|
|
import { generateEmbed } from "@/common/embed";
|
2024-04-17 17:21:15 +01:00
|
|
|
import { CachedPlayer, McUtilsAPIError, SkinPart, getPlayer } from "mcutils-library";
|
2024-04-16 17:54:22 +01:00
|
|
|
import { Metadata } from "next";
|
2024-04-16 18:49:23 +01:00
|
|
|
import Image from "next/image";
|
2024-04-16 23:16:34 +01:00
|
|
|
import Link from "next/link";
|
2024-04-16 17:54:22 +01:00
|
|
|
|
2024-04-16 18:07:29 +01:00
|
|
|
type Params = {
|
|
|
|
params: {
|
|
|
|
id: string;
|
|
|
|
};
|
2024-04-16 17:54:22 +01:00
|
|
|
};
|
|
|
|
|
2024-04-16 18:07:29 +01:00
|
|
|
export async function generateMetadata({ params: { id } }: Params): Promise<Metadata> {
|
2024-04-17 17:21:15 +01:00
|
|
|
try {
|
2024-04-17 17:41:55 +01:00
|
|
|
// No id provided
|
2024-04-17 17:26:10 +01:00
|
|
|
if (!id || id.length === 0) {
|
|
|
|
return generateEmbed({
|
2024-04-17 17:28:39 +01:00
|
|
|
title: "Player Lookup",
|
2024-04-17 17:26:10 +01:00
|
|
|
description: "Click to lookup a player.",
|
|
|
|
});
|
|
|
|
}
|
2024-04-17 17:21:15 +01:00
|
|
|
const player = await getPlayer(id);
|
2024-04-16 18:07:29 +01:00
|
|
|
|
2024-04-17 17:21:15 +01:00
|
|
|
const { username, uniqueId, skin } = player;
|
|
|
|
const headPartUrl = skin.parts.head;
|
2024-04-16 18:07:29 +01:00
|
|
|
|
2024-04-17 17:23:03 +01:00
|
|
|
const description = `UUID: ${uniqueId}\n\nClick to view more information about the player.`;
|
2024-04-16 18:07:29 +01:00
|
|
|
|
2024-04-17 17:21:15 +01:00
|
|
|
return generateEmbed({
|
|
|
|
title: `${username}`,
|
|
|
|
description: description,
|
|
|
|
image: headPartUrl,
|
|
|
|
});
|
|
|
|
} catch (err) {
|
2024-04-17 17:41:55 +01:00
|
|
|
// An error occurred
|
2024-04-17 17:21:15 +01:00
|
|
|
return generateEmbed({
|
|
|
|
title: "Player Not Found",
|
|
|
|
description: (err as McUtilsAPIError).message,
|
|
|
|
});
|
|
|
|
}
|
2024-04-16 17:54:22 +01:00
|
|
|
}
|
|
|
|
|
2024-04-17 17:21:15 +01:00
|
|
|
export default async function Page({ params: { id } }: Params): Promise<JSX.Element> {
|
|
|
|
let error: string | undefined = undefined; // The error to display
|
|
|
|
let player: CachedPlayer | undefined = undefined; // The player to display
|
2024-04-16 23:45:54 +01:00
|
|
|
|
2024-04-17 17:21:15 +01:00
|
|
|
// Try and get the player to display
|
2024-04-16 23:45:54 +01:00
|
|
|
try {
|
2024-04-17 17:21:15 +01:00
|
|
|
player = id ? await getPlayer(id) : undefined;
|
2024-04-16 23:45:54 +01:00
|
|
|
} catch (err) {
|
2024-04-17 17:21:15 +01:00
|
|
|
error = (err as McUtilsAPIError).message; // Set the error message
|
2024-04-16 23:45:54 +01:00
|
|
|
}
|
2024-04-16 17:54:22 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="h-full flex flex-col items-center">
|
|
|
|
<div className="mb-4 text-center">
|
|
|
|
<h1 className="text-xl">Lookup a Player</h1>
|
|
|
|
<p>You can enter a players uuid or username to get information about the player.</p>
|
2024-04-16 19:03:11 +01:00
|
|
|
|
|
|
|
<LookupPlayer />
|
2024-04-16 17:54:22 +01:00
|
|
|
</div>
|
|
|
|
|
2024-04-17 17:21:15 +01:00
|
|
|
{error && <ErrorCard message={error} />}
|
|
|
|
{player != undefined && (
|
|
|
|
<Card className="w-max xs:w-fit">
|
2024-04-16 21:50:08 +01:00
|
|
|
<div className="flex gap-4 flex-col xs:flex-row">
|
|
|
|
<div className="flex justify-center xs:justify-start">
|
2024-04-16 18:49:23 +01:00
|
|
|
<Image
|
2024-04-16 18:51:46 +01:00
|
|
|
className="w-[96px] h-[96px]"
|
2024-04-16 18:49:23 +01:00
|
|
|
src={player.skin.parts.head}
|
|
|
|
width={96}
|
|
|
|
height={96}
|
2024-04-16 19:48:15 +01:00
|
|
|
quality={100}
|
2024-04-16 18:49:23 +01:00
|
|
|
alt="The player's skin"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2024-04-17 18:26:53 +01:00
|
|
|
<div className="flex flex-col gap-2">
|
2024-04-16 18:49:23 +01:00
|
|
|
<div>
|
2024-04-17 18:26:53 +01:00
|
|
|
<h2 className="text-xl text-primary font-semibold">{player.username}</h2>
|
2024-04-17 04:07:39 +01:00
|
|
|
<p>{player.uniqueId}</p>
|
2024-04-16 18:49:23 +01:00
|
|
|
</div>
|
|
|
|
|
2024-04-17 18:26:53 +01:00
|
|
|
<Separator />
|
|
|
|
|
2024-04-16 18:49:23 +01:00
|
|
|
<div className="flex flex-col gap-2">
|
2024-04-17 18:26:53 +01:00
|
|
|
<p className="text-lg">Skin Parts</p>
|
2024-04-16 18:49:23 +01:00
|
|
|
<div className="flex gap-2">
|
2024-04-16 23:10:15 +01:00
|
|
|
{Object.entries(player.skin.parts)
|
2024-04-16 23:27:33 +01:00
|
|
|
.filter(([part]) => part !== SkinPart.HEAD) // Don't show the head part again
|
2024-04-16 23:16:34 +01:00
|
|
|
.map(([part, url]) => {
|
2024-04-16 23:10:15 +01:00
|
|
|
return (
|
2024-04-17 18:08:13 +01:00
|
|
|
<Tooltip key={part}>
|
|
|
|
<TooltipTrigger>
|
|
|
|
<Link href={url} target="_blank">
|
|
|
|
<img className="h-[64px]" src={url} alt={`The player's ${part}`} loading="lazy" />
|
|
|
|
</Link>
|
|
|
|
</TooltipTrigger>
|
|
|
|
<TooltipContent>
|
|
|
|
<p>
|
|
|
|
Click to view {player.username}'s {part}
|
|
|
|
</p>
|
|
|
|
</TooltipContent>
|
|
|
|
</Tooltip>
|
2024-04-16 23:10:15 +01:00
|
|
|
);
|
|
|
|
})}
|
2024-04-16 18:49:23 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-16 17:54:22 +01:00
|
|
|
</div>
|
2024-04-17 17:21:15 +01:00
|
|
|
</Card>
|
|
|
|
)}
|
2024-04-16 17:54:22 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|