How to optimize land protection plugin?

Discussion in 'Spigot Plugin Development' started by MrHardyCZ, Mar 1, 2020.

  1. Hello,
    I've created land claiming and protecting plugin called 'ForceFields' which is based exchaning items (fuel) for land protection.
    But my plugin creates a lot of lag, when players create a lot of forcefields.
    How can I optimize such plugin?

    The way I'm currently handling the events is by creating instance of class ForceField, which takes parameters like position and it registeres every event such as blockBreak, blockPlace etc. by itself. So in the end, there are hundrets of instances with hundrets of listerens for the same events. I would should piece of the code, but I don't think it's all that neccessery, because it's only like 900 lines of events handelers.

    My plugin: https://www.mc-market.org/resources/11062/
     
    #1 MrHardyCZ, Mar 1, 2020
    Last edited: Mar 1, 2020
    • Funny Funny x 2
  2. So skipping the fact that you are marking it as resource,you need help with a plugin outside of spigot?

    Also all your giving is a link to your plugin,no code on how you handle the events or any attempts?
     
  3. drives_a_ford

    Moderator

    First of all, this is not a resource - remove that tag. The tag is reserved for posts describing a resource on how to do something.

    As for your problem, it's impossible to tell what you're doing wrong without the source code.
     
  4. Hello, I removed the tag.
    The way I'm handling the events is by creating instance of class ForceField, which takes parameters like position and it registeres every event like blockBreak, blockPlace etc. by itself. So in the end, there will be hundrets of instances with hundrets of listerens for the same events.
    When I'm home, I can send you piece of the code, but I don't think it's all that neccessery, because it's only like 900 lines of events handelers.
     
  5. Hey, I removed the tag. The plugin is not on spigot, because it wasn't approved. I'm asking for help on spigot forums, because it has bigger community.

    The way I'm handling the events is by creating instance of class ForceField, which takes parameters like position and it registeres every event like blockBreak, blockPlace etc. by itself. So in the end, there are hundrets of instances with hundrets of listerens for the same events.
    When I'm home, I can send you piece of the code, but I don't think it's all that neccessery, because it's only like 900 lines of event handelers.
     
  6. drives_a_ford

    Moderator

    It really depends on what is in those event listeners.
    But I would generally avoid creating hundreds of new listeners and just have one listener that knows to listen to specific things that are to do with each special something. Right now it's likely you're doing the same calculations over and over again for different instances. Whereas if you had just one listener, you might get away with doing some of those calculations just once.

    Or it's possible your code is just terribly inefficient.

    But it's impossible to tell without seeing the code.
     
  7. We can't just guess, show us the code!