CanRenameBed
CanRenameBed is called when a player submits a new name for a sleeping bag or bed via SleepingBag.Rename; returning a non-null value cancels the rename before filtering and assignment.
object CanRenameBed(BasePlayer player, SleepingBag sleepingBag, string text)Parameters
| Parameter | Type | Description |
|---|---|---|
player | BasePlayer | The BasePlayer sending the rename request. Use it for permission checks, team lookups or ownership validation. |
sleepingBag | SleepingBag | The SleepingBag entity being renamed. Use its OwnerID, net.ID or position to decide whether the rename is allowed. |
text | string | The raw name the player submitted, already read from the network message but not yet passed through WordFilter. You can inspect or validate it here. |
Return value
Returning null lets the rename continue through filtering and assignment. Any non-null return value aborts the rename, so the bed keeps its old name. Note that false is still a non-null value, so it also cancels the rename; only null allows it through.
How it works
This hook fires inside SleepingBag.Rename, after the server has confirmed the player can physically access the bed but before the submitted text is run through WordFilter and written to the entity. It fires for every rename attempt a client sends, whether the target is a Sleeping Bag, Bed, Camper or other SleepingBag-derived deployable.
player is the renaming player, sleepingBag is the target entity and text is the raw, unfiltered string. Returning anything other than null tells the game to skip the rest of the rename, so the bed keeps its current name. Declaring player as a more specific type rarely helps since it is always a BasePlayer; narrowing sleepingBag to a subtype would only match that subtype.
The hook fires before filtering, so the text you see may contain blocked words or be empty. Use it to enforce ownership policy, name length limits, reserved names or team-scoping rules rather than to sanitize content (the game already does that afterward).
Example plugin: Restrict bed renaming to the owner's team
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Bed Rename Guard", "RustPluginGenerator", "1.0.0")]
[Description("Restricts renaming of sleeping bags and beds by ownership and name length.")]
public class BedRenameGuard : RustPlugin
{
private const string PermBypass = "bedrenameguard.bypass";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Require ownership to rename")]
public bool RequireOwnership = true;
[JsonProperty("Allow teammates to rename each other's beds")]
public bool AllowTeammates = true;
[JsonProperty("Maximum name length")]
public int MaxNameLength = 24;
}
protected override void LoadDefaultConfig() => config = new PluginConfig();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<PluginConfig>();
if (config == null) throw new Exception();
}
catch
{
PrintWarning("Configuration file is invalid, using defaults");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(config);
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["NotOwner"] = "You can only rename beds you own.",
["TooLong"] = "That name is too long. Maximum is {0} characters."
}, this);
}
private string Msg(string key, string userId = null, params object[] args) =>
string.Format(lang.GetMessage(key, this, userId), args);
private void Init()
{
permission.RegisterPermission(PermBypass, this);
}
private object CanRenameBed(BasePlayer player, SleepingBag sleepingBag, string text)
{
if (player == null || sleepingBag == null) return null;
if (player.IsAdmin || permission.UserHasPermission(player.UserIDString, PermBypass)) return null;
if (config.MaxNameLength > 0 && text != null && text.Length > config.MaxNameLength)
{
player.ChatMessage(Msg("TooLong", player.UserIDString, config.MaxNameLength));
return false;
}
if (!config.RequireOwnership) return null;
ulong playerId = player.userID.Get();
if (sleepingBag.OwnerID == playerId) return null;
if (config.AllowTeammates && player.currentTeam != 0)
{
var team = RelationshipManager.ServerInstance.FindTeam(player.currentTeam);
if (team != null && team.members.Contains(sleepingBag.OwnerID)) return null;
}
player.ChatMessage(Msg("NotOwner", player.UserIDString));
return false;
}
}
}The plugin inspects every rename attempt in CanRenameBed. It reads the configured rules from oxide/config: whether to block renaming of beds the caller doesn't own and whether to cap the submitted name length. When a rule is violated it sends a localized chat message to the player and returns a non-null value, which stops the rename before the name is written. Legitimate renames return null and proceed as usual through the game's filtering. The owner fallback uses player.userID compared against sleepingBag.OwnerID to avoid the entity being renamed by a player who merely shares access.
Common use cases
Team-only bed names
Block players from renaming a teammate's bed by comparing the owner's
OwnerIDto the caller's team viaRelationshipManager.ServerInstance.FindTeam.Name length cap
Reject overly long names that widen UI rows or break layouts in some sleep menus, then return a non-null value to keep the current name.
Reserved name audit
Deny names matching admin-defined reserved words such as 'Free Kits' or 'Trade Here' to prevent scam signage on deployables.
Pitfalls
Text is unfiltered
textarrives beforeWordFilter.Filter, so blocked words, control characters or whitespace-only strings can appear. Validate for policy, don't try to reproduce filtering.Returning false still cancels
The game only proceeds with the rename when the hook returns null. Returning
falseis a non-null value and therefore still aborts the rename.Fires on every keystroke commit
Rename UI typically submits once, but a spammy client can trigger many calls. Avoid heavy lookups inside the hook and don't
Putshere on every call.
Build a plugin with CanRenameBed
Describe what should happen and get a compiled plugin that uses this hook.
Edit the prompt on the next screen. 2 free plugins a month, no card.
Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.
Build a plugin with CanRenameBed
Generate