Un-setting player attributes

  • Sometime, it is convenient to either un-set a player attribute (and to be able to test for it to return null) or to remove the reference to an object stored in an attribute and allowing it to be garbage collected when no longer used (particularly a non-primitive object type, like a GuiElement).


    There are work-around, of course: a primitive type can be set to a specific, "none", value (e.g., with a Boolean or an Integer); an attribute supposed to contain a complex type can be set to a Boolean "false" and checked for being null or an instance of Boolean, and so on. However, these are ad-hoc solutions, obfuscating the code and increasing maintenance complexity.


    Currently, it is not possible to set an attribute to null, which would be the easiest and clearest solution.


    The request is then to either:


    1) allowing to set an attribute to a null value (from the consumer perspective, it is irrelevant if this results in the attribute being physically removed form the attribute collection or in it remaining there and being assigned an actual null value, as long as getting it back returns null)


    OR


    2) allowing to un-set an attribute via a specific Player.unsetAttribute(String attributeName) method.



    I hope the use cases are clear enough. If not, I could elaborate them further.

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!