[Closed] Is this bad performance?

Discussion in 'Spigot Plugin Development' started by BryceTheCoder, May 13, 2015.

  1. Hello everyone!
    I am attempting to make an armor system for my RPG server.
    What I am currently doing is simply,
    (pseudo code)
    if (gotHit = player) {
    armor += getArmorLore(helm);
    armor += getArmorLore(chest);
    armor += getArmorLore(legs);
    armor += getArmorLore(boots);
    damage = getDamage - armor;
    }

    The only thing I can think of why this could possibly be bad for performance would be getting the lore of 4 items EVERY time you hit a player. Would this still be okay for performance? Or would this get bad for my server? Any thoughts for improvement?
     
  2. I'm lost of why you would want me to use a StringBuilder.
    I am not dealing with ANY strings whatsoever.
    I'm attempting to get all the armor stats on the objects worn by the player, then affect the damage accordingly.
    In what way would a StringBuilder help me out?
     
  3. mfw +=, but not strings == dafuq u trying do.

    ot: it seems like you need to go back to the basics of java, seeing as you dont understand that arithmetic operators cannot be applied to objects
     
    • Like Like x 1
  4. I'd assume he somehow stores a number in the item lore and casts it to an integer or something. He did wrote "Pseudo-code".
     
  5. You should show what gotHit and armor is e.g. what object
     
  6. Lmfao, buddy I am getting a degree in ComputerScience and all I do is program in Java.
    You shouldn't try and tell me that my programming skills are elementary, and to go back to the basics simply because you could not understand what is going on.
    The method (not an object) "getArmorLore" is a double.
    I'm not getting any errors with this..... my armor system is working 100% exactly how I want it to. However, I'm posting here to see if anyone has a more efficient way of doing it.
    Just don't be so rude, I don't care if this is the internet or not.
     
    • Funny Funny x 2
    • Optimistic Optimistic x 2
  7. With that attitude, a degree in computer science won't help you in life.
     
    • Like Like x 1
  8. If you don't want to get it every time, then you could simply keep a cache of their armor stats which is updated when their armor is changed.

    However (depending on your implementation) it's a miniscule amount of work to parse a string list, you wouldn't see much of a speed benefit for the tradeoff in memory usage.
     
    • Agree Agree x 1
  9. Lol lets all be stupid and name things with the implication of returning a string, yet return a number primitive instead. herp derp im smart

    Seriously, how is one supposed to understand how somethings going on if the code (pseudo or not) is not even close to clear. Its not a mystery as to why 1Rogue and I assumed you were discussing strings. Because you can't use appropriate naming conventions.

    And as 1Rogue said, caching won't be more efficient except in the case of the parsing being done more than it should be.
     
  10. If you were getting a degree in Computer Science, then you would know that you can't do that.
     
  11. Well as far as I can think of your options are:
    - keeping track of the total 'armor values' of players, by listening to inventoryclick events; but this is probably worse because of the extra listeners and memory usage.
    - read the lore every hit. Honestly doesn't sound bad to me, gotta do what you need to know right.
    - Use NBT tags instead of lore. This will make your plugin version dependent (without reflection) but you can store 'invisible' data. I'm not sure if it will be better then lore, since lore is in turn also stored as NBT tags so it might be just the same, except that you don't have to parse from strings.

    TL;DR: I'd just keep doing what you're doing
     
  12. Haha, it's funny becuase you're still not understanding and yet still talking shit to me. If you didn't understand something, you need to ask, not be a dick.

    Well, thank God I didn't have an attitude. Simply just informing him not to be a dick.

    I should know I can't do that? I did do that, and its 100% functional.


    No one is understanding what the hell is going on, and people are just getting mad. I'm not coming back to this post again, so I'd recommend no one posting anymore on here either.
    I have had this armor system working perfectly since I posted this, just wanted an idea of what else people thought could be more efficient, however, I don't need any more ideas from you guys.
     
    • Funny Funny x 1
    • Optimistic Optimistic x 1
  13. Can't tell if trolling or just dumb.
     
    • Agree Agree x 1
  14. I'm laughing at how he thinks we're getting mad, when clearly he's the only mad one.

    ot: op if you want help, be clear with your code, question, and any other info you provide. Otherwise misunderstandings ensue.