Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions commands/pdc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from discord import app_commands
from discord.ext import commands
import discord
import utils


class PdcCog(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot
embed = discord.Embed(title="Persistent Data Tags (PDC)", color=bot.embed_color)
embed.set_footer(
text=bot.embed_footer,
icon_url=bot.embed_footer_url
)
embed.add_field(
name="What are Persistent Data Tags?",
value="Persistent data tags (PDC) store custom data directly on players, entities, items, chunks "
"and worlds. Think of one as a sticky note on the object itself: put a number on a sword and it "
"keeps that number when you drop it or move it between inventories. That makes them the best option "
"for item data, since items have no id you can use in a normal variable. This feature requires Skript 2.15+",
inline=False
)
usage = """
Every tag needs a key written as `namespace:key-name`. If you don't specify a namespace it will default to `minecraft:`. Once you have one you can set it and read it back:
```vb
set data tag "myserver:level" of player to 5
set {_level} to data tag "myserver:level" of player```
**To learn more you can read the [skriptlang pdc page](https://beta-docs.skriptlang.org/scripting/pdc/).**
"""
embed.add_field(
name="How to use them",
value=usage,
inline=False
)
syntax = """
- [Persistent Data Value](https://beta-docs.skriptlang.org/syntaxes/?search=%23ExprPersistentData): get, set and delete a tag.
- [Has Persistent Data Tag](https://beta-docs.skriptlang.org/syntaxes/?search=%23CondHasPersistentDataTag): check whether an object has a tag.
- [All Persistent Data Keys](https://beta-docs.skriptlang.org/syntaxes/?search=%23ExprAllPersistentDataKeys): every key stored on an object.
"""
embed.add_field(
name="Syntax",
value=syntax,
inline=False
)
embed.add_field(
name="Not NBT, not metadata",
value="PDC tags show up in an object's NBT, but reading and writing them skips the expensive rewrite that "
"editing NBT causes. They also fill the same role as metadata tags while surviving restarts, "
"and Paper is in the process of removing metadata, so please move any metadata you have over to PDC",
inline=False
)
self.embed = embed

@app_commands.command(description="Informational embed about persistent data tags")
@app_commands.describe(reply_to="The user you want to send this message to")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def pdc(self, interaction: discord.Interaction, reply_to: discord.User = None) -> None:
await utils.send(
interaction=interaction,
embed=self.embed,
ping=reply_to
)


async def setup(bot):
await bot.add_cog(PdcCog(bot=bot))