YourAverageNerd
Verified Member
Hello fellow human beings,
While working on an addon ability, I stumbled upon something that, in my opinion, the API lacks. So I was told that the API is really clean and easy to use since an addon only requires 1 class. This was very nice to hear and I was looking forward to a clean design and easy to use structure. I'm completely satisfied with some sides of it, but at the same sides disappointed by other sides. Allow me to explain and suggest my solutions.
There are 2 things I was disappointed about. These 2 things are Listeners/activation and TempBlocks.
Listener:
If you're a developer and reading this, you probably know what a Listener is. For those who don't know, it's used to 'listen' for when something happens, AKA when an event is fired. The most used events for ability activation are 'PlayerAnimationEvent' (when a player left clicks) and 'PlayerToggleSneakEvent' (when a player toggles sneaking). Now, a method for either or both of these events has to be made somewhere. One could just go ahead and make the class implement Listener and put the methods in there, but I found it became quite messy quite quickly, because you also have to check if they have the ability bound, can bend in that area, etc, etc. I'd like to propose a solution to this.
There will be 2 abstract methods in CoreAbility, or another implementation of Ability that the developers see fit. These methods will be called 'click(Player)' and 'sneak(Player)'. In PK's Listener, there would be a check to see if the event's player has an addon ability bound, if so it gets that ability and calls either 'click(Player)' or 'sneak(Player)', depending on the event's type. Before calling one of these methods, it would also check if they are allowed to use the move, if they can bend in that area, and all the other checks, due to the method being called from PK's listener.
Pros:
TempBlocks:
Now, for TempBlocks. Don't get me wrong, they are great, really. They are already extremely useful and I love them. I just have 1 problem with them, and that's the removal/reverting of TempBlocks. I have to keep track of them, and revert them manually. I think it would be great if there was an additional constructor with a 'time' argument, which specifies after how many ticks or milliseconds the TempBlock should revert to it's original state. I believe currently all addons and stock abilities have to do this themselves, which I think is not a great thing. I suggest there is 1 central map in the TempBlock class or in a TempBlockManager class, which keeps track of all TempBlocks, and will revert them if they have a revert time specified and if that time has ran out.
Pros:
Thank you for reading my suggestions! In my opinion, the first one is a bit more important than the second, yet I still think they will both be useful.
Please let me know what you think and if you think this idea can be improved! Thanks in advance.
~~ YourAverageNerd ~~
While working on an addon ability, I stumbled upon something that, in my opinion, the API lacks. So I was told that the API is really clean and easy to use since an addon only requires 1 class. This was very nice to hear and I was looking forward to a clean design and easy to use structure. I'm completely satisfied with some sides of it, but at the same sides disappointed by other sides. Allow me to explain and suggest my solutions.
There are 2 things I was disappointed about. These 2 things are Listeners/activation and TempBlocks.
Listener:
If you're a developer and reading this, you probably know what a Listener is. For those who don't know, it's used to 'listen' for when something happens, AKA when an event is fired. The most used events for ability activation are 'PlayerAnimationEvent' (when a player left clicks) and 'PlayerToggleSneakEvent' (when a player toggles sneaking). Now, a method for either or both of these events has to be made somewhere. One could just go ahead and make the class implement Listener and put the methods in there, but I found it became quite messy quite quickly, because you also have to check if they have the ability bound, can bend in that area, etc, etc. I'd like to propose a solution to this.
There will be 2 abstract methods in CoreAbility, or another implementation of Ability that the developers see fit. These methods will be called 'click(Player)' and 'sneak(Player)'. In PK's Listener, there would be a check to see if the event's player has an addon ability bound, if so it gets that ability and calls either 'click(Player)' or 'sneak(Player)', depending on the event's type. Before calling one of these methods, it would also check if they are allowed to use the move, if they can bend in that area, and all the other checks, due to the method being called from PK's listener.
Pros:
- Less messy in the addon's code.
- Less registered listeners.
- Less calls to 'heavy' methods such as 'isRegionProtectedFromBuild' (last time I checked it was quite the heavy method )
- There probably are some, but I really can't think of any at the moment.
TempBlocks:
Now, for TempBlocks. Don't get me wrong, they are great, really. They are already extremely useful and I love them. I just have 1 problem with them, and that's the removal/reverting of TempBlocks. I have to keep track of them, and revert them manually. I think it would be great if there was an additional constructor with a 'time' argument, which specifies after how many ticks or milliseconds the TempBlock should revert to it's original state. I believe currently all addons and stock abilities have to do this themselves, which I think is not a great thing. I suggest there is 1 central map in the TempBlock class or in a TempBlockManager class, which keeps track of all TempBlocks, and will revert them if they have a revert time specified and if that time has ran out.
Pros:
- Abilities don't have to keep track of TempBlocks individually.
- Again, I can't really think of any at this moment.
Thank you for reading my suggestions! In my opinion, the first one is a bit more important than the second, yet I still think they will both be useful.
Please let me know what you think and if you think this idea can be improved! Thanks in advance.
~~ YourAverageNerd ~~