Skip to content

[BUG]: Missing setter overrides for ChamberMax, ChamberedAmmo, and Cocked in ParticleDisruptorItem cause console errors #401

@efrosim

Description

@efrosim

Before You Report

  • I have searched for existing reports of this bug, and this bug report is unique.

Version

1.1.6

Description

The ParticleDisruptorItem class overrides the ChamberMax, ChamberedAmmo, and Cocked properties but only provides a get accessor for them. Because the base class (FirearmItem) has both get and set for these properties, attempting to set any of them on a ParticleDisruptorItem falls back to the base class setter.

The base class setters attempt to cast the ActionModule to AutomaticActionModule, which fails for the Disruptor (since it uses DisruptorActionModule), resulting in an internal LabAPI error logged to the server console.

To Reproduce

  1. Obtain a ParticleDisruptorItem instance.
  2. Attempt to set its ChamberMax, ChamberedAmmo, or Cocked property (e.g., disruptor.ChamberMax = 5; or disruptor.Cocked = true;).
  3. Check the server console. You will see the following error:
    [ERROR] [LabApi] Unable to set <PropertyName> as this firearm's IActionModule is not valid.

Expected Behavior

Setting these properties on a Particle Disruptor should either be ignored silently (since it's a special weapon with fixed mechanics) or throw a clear NotSupportedException without falling back to the incompatible base class logic.

Additional Information

Proposed Fix

In LabApi\Features\Wrappers\Items\Firearm\SpecialFirearms\ParticleDisruptorItem.cs:

Add setters that throw a NotSupportedException to override the base class behavior and clearly indicate invalid operations.

Proposed fix:

    public override int ChamberedAmmo
    {
        get
        {
            if (ActionModule is DisruptorActionModule actionModule)
            {
                return actionModule.IsLoaded ? 1 : 0;
            }
            return 0;
        }
        set => throw new NotSupportedException("ChamberedAmmo cannot be modified for the Particle Disruptor.");
    }

    public override int ChamberMax
    {
        get => 1;
        set => throw new NotSupportedException("ChamberMax cannot be modified for the Particle Disruptor.");
    }

    public override bool Cocked
    {
        get
        {
            if (ActionModule is DisruptorActionModule actionModule)
            {
                return actionModule.IsLoaded;
            }
            return false;
        }
        set => throw new NotSupportedException("Cocked state cannot be modified for the Particle Disruptor.");
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions