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-18 04:32:30 +01:00
|
|
|
import { CodeDialog } from "@/app/components/code-dialog";
|
2024-04-18 02:07:02 +01:00
|
|
|
import { CopyButton } from "@/app/components/copy-button";
|
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-18 02:07:02 +01:00
|
|
|
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/app/components/ui/context-menu";
|
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-18 06:33:30 +01:00
|
|
|
import { Colors } from "@/common/colors";
|
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-18 06:33:30 +01:00
|
|
|
import { Metadata, Viewport } 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-18 01:21:38 +01:00
|
|
|
import { ReactElement } from "react";
|
2024-04-18 02:07:02 +01:00
|
|
|
import config from "../../../../../config.json";
|
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-18 06:33:30 +01:00
|
|
|
export async function generateViewport({ params: { id } }: Params): Promise<Viewport> {
|
|
|
|
try {
|
|
|
|
if (!id || id.length === 0) {
|
|
|
|
return {
|
|
|
|
themeColor: Colors.red,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
await getPlayer(id); // Ensure the player is valid.
|
|
|
|
return {
|
|
|
|
themeColor: Colors.green,
|
|
|
|
};
|
|
|
|
} catch (err) {
|
|
|
|
// An error occurred
|
|
|
|
return {
|
|
|
|
themeColor: Colors.red,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-18 01:21:38 +01:00
|
|
|
export default async function Page({ params: { id } }: Params): Promise<ReactElement> {
|
2024-04-17 17:21:15 +01:00
|
|
|
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 && (
|
2024-04-18 02:07:02 +01:00
|
|
|
<ContextMenu>
|
|
|
|
<ContextMenuTrigger>
|
|
|
|
<Card className="w-max xs:w-fit">
|
2024-04-18 04:32:30 +01:00
|
|
|
<div className="flex gap-4 flex-col xs:flex-row relative">
|
|
|
|
<div className="absolute 8xl:top-0 xs:bottom-0">
|
|
|
|
<CodeDialog
|
|
|
|
title="Player Data"
|
|
|
|
description="The player's data from the API"
|
|
|
|
code={JSON.stringify(player, undefined, 2)}
|
|
|
|
>
|
|
|
|
<button className="bg-background rounded-lg">
|
|
|
|
<p className="p-1">JSON</p>
|
|
|
|
</button>
|
|
|
|
</CodeDialog>
|
|
|
|
</div>
|
|
|
|
|
2024-04-18 02:07:02 +01:00
|
|
|
<div className="flex justify-center xs:justify-start">
|
|
|
|
<Image
|
|
|
|
className="w-[96px] h-[96px]"
|
|
|
|
src={player.skin.parts.head}
|
|
|
|
width={96}
|
|
|
|
height={96}
|
|
|
|
quality={100}
|
|
|
|
alt="The player's skin"
|
|
|
|
/>
|
|
|
|
</div>
|
2024-04-16 18:49:23 +01:00
|
|
|
|
2024-04-18 02:07:02 +01:00
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
<div>
|
|
|
|
<h2 className="text-xl text-primary font-semibold">{player.username}</h2>
|
|
|
|
<p>{player.uniqueId}</p>
|
|
|
|
</div>
|
2024-04-16 18:49:23 +01:00
|
|
|
|
2024-04-18 02:07:02 +01:00
|
|
|
<Separator />
|
2024-04-17 18:26:53 +01:00
|
|
|
|
2024-04-18 02:07:02 +01:00
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
<p className="text-lg">Skin Parts</p>
|
|
|
|
<div className="flex gap-2">
|
|
|
|
{Object.entries(player.skin.parts)
|
|
|
|
.filter(([part]) => part !== SkinPart.HEAD) // Don't show the head part again
|
|
|
|
.map(([part, url]) => {
|
|
|
|
return (
|
|
|
|
<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>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-16 18:49:23 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-18 02:07:02 +01:00
|
|
|
</Card>
|
|
|
|
</ContextMenuTrigger>
|
|
|
|
<ContextMenuContent className="flex flex-col">
|
|
|
|
<CopyButton content={player.username}>
|
|
|
|
<ContextMenuItem>Copy Player Username</ContextMenuItem>
|
|
|
|
</CopyButton>
|
|
|
|
|
|
|
|
<CopyButton content={player.uniqueId}>
|
|
|
|
<ContextMenuItem>Copy Player UUID</ContextMenuItem>
|
|
|
|
</CopyButton>
|
|
|
|
|
|
|
|
<CopyButton content={`${config.siteUrl}/player/${id}`}>
|
|
|
|
<ContextMenuItem>Copy Share URL</ContextMenuItem>
|
|
|
|
</CopyButton>
|
|
|
|
</ContextMenuContent>
|
|
|
|
</ContextMenu>
|
2024-04-17 17:21:15 +01:00
|
|
|
)}
|
2024-04-16 17:54:22 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|