From 47892d116b9f6b199cda0e481b2bf056b2c97f86 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 27 Apr 2026 00:11:02 -0600 Subject: [PATCH] Prevent non-GMs from making attributes when the setting is disabled. --- langs/en-ca.json | 3 ++- module/data/Item/attribute.mjs | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/langs/en-ca.json b/langs/en-ca.json index 5cb4cd5..f34f8e0 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -137,7 +137,8 @@ "invalid-socket": "Invalid socket data received, this means a module or system bug is present.", "unknown-socket-event": "An unknown socket event was received: {event}", "duplicate-attribute-key": "Cannot create an Attribute with a key (\"{key}\") that already exists on the Actor", - "invalid-attribute-key": "Attribute keys must be alphanumeric (a-z, 0-9) with underscores, invalid key provided: \"{key}\"" + "invalid-attribute-key": "Attribute keys must be alphanumeric (a-z, 0-9) with underscores, invalid key provided: \"{key}\"", + "cant-manage-attributes": "You aren't allowed to manage attributes. Talk to your GM for permission or to get them to add the attribute for you." }, "warn": { "migration-in-progress": "Applying data migrations for version {version}. Please do NOT refresh the window while this warning is present." diff --git a/module/data/Item/attribute.mjs b/module/data/Item/attribute.mjs index 91ebcb5..cfcbecb 100644 --- a/module/data/Item/attribute.mjs +++ b/module/data/Item/attribute.mjs @@ -1,4 +1,5 @@ import { isValidID, toID } from "../../utils/toID.mjs"; +import { __ID__ } from "../../consts.mjs"; import { clamp } from "../../utils/clamp.mjs"; const { getProperty, hasProperty, setProperty } = foundry.utils; @@ -41,6 +42,15 @@ export class AttributeItemData extends foundry.abstract.TypeDataModel { // #region Lifecycle async _preCreate(data, options, user) { + // Prevent users from creating attributes if disallowed + if ( + !game.settings.get(__ID__, `canPlayersManageAttributes`) + && !user.isGM + ) { + ui.notifications.error(_loc(`taf.notifs.error.cant-manage-attributes`)); + return false; + }; + // Assign the key as the ID'd name if isn't provided, or validate if // it is provided. if (!this.key) {