namespace Oxide.Plugins;

[Info("No Player Loot", "&anhe", "1.2.0")]
[Description("Prevents players from looting others.")]
public class NoPlayerLoot : RustPlugin
{
    private object CanLootPlayer(BasePlayer target, BasePlayer looter) =>
        // Allow if
        (
            // Team (Asleep)
            (
                looter.currentTeam != 0 &&
                target.currentTeam == looter.currentTeam
            ) ||
            // Hands up (Awake)
            !target.IsSleeping() ||
            // Admin
            looter.IsAdmin
        )
            ? null : false;

    private object CanLootUnalived(ulong targetId, BasePlayer looter) =>
        // Allow if
        (
            // NPC
            targetId < 76561197960265728 ||
            // Self
            looter.userID == targetId ||
            // Team
            looter.Team?.members.Contains(targetId) == true ||
            // Admin
            looter.IsAdmin
        )
            ? null : false;

    private object CanLootEntity(BasePlayer looter, LootableCorpse entity) =>
        CanLootUnalived(entity.playerSteamID, looter);

    private object CanLootEntity(BasePlayer looter, DroppedItemContainer entity) =>
        CanLootUnalived(entity.playerSteamID, looter);
}