private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
{
if (entity is BuildingBlock || entity.name.Contains("deploy") || entity.name.Contains("building"))
{
var player = info?.Initiator?.ToPlayer();
if (!player || player.IsNpc || !entity.OwnerID.IsSteamId())
{
return null;
}
if (cFile.FriendBypass.Enabled)
{
// Owner checks
if (cFile.FriendBypass.PlayerOwner.Enabled && player.userID == entity.OwnerID)
{
return null;
}
// NEW: Twig griefing protection via building ID match
if (entity is BuildingBlock block && block.grade == BuildingGrade.Enum.Twigs)
{
var building = block.GetBuilding();
if (building != null)
{
foreach (var part in building.buildingBlocks)
{
if (part != null && part.OwnerID == player.userID && part.net.ID != block.net.ID)
{
// Player owns part of this structure, allow them to remove the twig
return null;
}
}
}
}
// Friend checks
if (Friends)
{
var hasFriend = Friends?.Call("HasFriend", entity.OwnerID.ToString(), player.UserIDString) ?? false;
if (cFile.FriendBypass.FriendsApi.Enabled && (bool)hasFriend)
{
return null;
}
}
if (Clans)
{
var targetClan = (string)Clans?.Call("GetClanOf", entity.OwnerID.ToString());
var playerClan = (string)Clans?.Call("GetClanOf", player.UserIDString);
if (cFile.FriendBypass.RustIoClans.Enabled && playerClan != null && targetClan != null && targetClan == playerClan)
{
return null;
}
}
}
// Prevents player from damaging after friendbypass checks
if (cFile.StopAllRaiding)
{
PrintToChat(player, Lang("CantDamage", player.UserIDString));
return true;
}
// No raid command checks
if (!_canRaid)
{
PrintToChat(player, Lang("Cmd_CantRaid", player.UserIDString, GetFormattedTime((_cachedRaidTime.AddMinutes(_startMinutes)
- DateTime.UtcNow).TotalSeconds)));
return true;
}
// Wipe raid checks
if (cFile.WipeRaiding.Enabled && !_canWipeRaid)
{
PrintToChat(player, Lang("Cmd_CantRaid", player.UserIDString, GetFormattedTime((_cachedWipeTime.AddMinutes(cFile.WipeRaiding.MinsFromWipe)
- DateTime.UtcNow).TotalSeconds)));
return true;
}
if (cFile.WipeRaiding.Enabled)
{
return null;
}
}
return null;
}
=====
This checks a twigs structure owner id vs the base id its attached to.
If the twig is made by someone other than the owner, they can now damage it.
cheers