Problem by checking Signs

Discussion in 'Plugin Development' started by PreFiXAUT, Dec 31, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    PreFiXAUT

    Hello everyone! I started making an Plugin again, and this time I'm realy out of Ideas...again.
    I'm trying to check if there are Signs which are straigt vertical (like floors), and you're able to teleport to them.
    Anyway, I got nearly everything I wanted, exept I'm having troubles saving them as groups, to get all aviable floors.
    Source Codes:
    http://pastebin.com/CtHbMrR8
    SignClickListener: http://pastebin.com/tRN3HufY

    Is there a way to save it easier/better to access.
    I'm also confused with this part:
    Show Spoiler
    Code:java
    1. if (sign1loc == null)
    2. {
    3. sign1loc = sign.getLocation();
    4. if (sign.getLine(1) != null) sign1text = sign.getLine(1);
    5. if (sign.getLine(2) != null) sign1item = Integer.parseInt(sign.getLine(2));
    6. }
    7. else if (sign2loc == null && this.isOnSamePosition(sign1loc, sign.getLocation()))
    8. {
    9. sign2loc = sign.getLocation();
    10. if (sign.getLine(1) != null) sign2text = sign.getLine(1);
    11. if (sign.getLine(2) != null) sign2item = Integer.parseInt(sign.getLine(2));
    12. }
    13. else if (sign3loc == null && this.isOnSamePosition(sign1loc, sign.getLocation()))
    14. {
    15. sign3loc = sign.getLocation();
    16. if (sign.getLine(1) != null) sign3text = sign.getLine(1);
    17. if (sign.getLine(2) != null) sign3item = Integer.parseInt(sign.getLine(2));
    18. }
    19. else if (sign4loc == null && this.isOnSamePosition(sign1loc, sign.getLocation()))
    20. {
    21. sign4loc = sign.getLocation();
    22. if (sign.getLine(1) != null) sign4text = sign.getLine(1);
    23. if (sign.getLine(2) != null) sign4item = Integer.parseInt(sign.getLine(2));
    24. }
    25. else if (sign5loc == null && this.isOnSamePosition(sign1loc, sign.getLocation()))
    26. {
    27. sign5loc = sign.getLocation();
    28. if (sign.getLine(1) != null) sign5text = sign.getLine(1);
    29. if (sign.getLine(2) != null) sign5item = Integer.parseInt(sign.getLine(2));
    30. }
    31. else if (sign6loc == null && this.isOnSamePosition(sign1loc, sign.getLocation()))
    32. {
    33. sign6loc = sign.getLocation();
    34. if (sign.getLine(1) != null) sign6text = sign.getLine(1);
    35. if (sign.getLine(2) != null) sign6item = Integer.parseInt(sign.getLine(2));
    36. }
    37. else if (sign7loc == null && this.isOnSamePosition(sign1loc, sign.getLocation()))
    38. {
    39. sign7loc = sign.getLocation();
    40. if (sign.getLine(1) != null) sign7text = sign.getLine(1);
    41. if (sign.getLine(2) != null) sign7item = Integer.parseInt(sign.getLine(2));
    42. }
    43. else if (sign8loc == null && this.isOnSamePosition(sign1loc, sign.getLocation()))
    44. {
    45. sign8loc = sign.getLocation();
    46. if (sign.getLine(1) != null) sign8text = sign.getLine(1);
    47. if (sign.getLine(2) != null) sign8item = Integer.parseInt(sign.getLine(2));
    48. }
    49. else if (sign9loc == null && this.isOnSamePosition(sign1loc, sign.getLocation()))
    50. {
    51. sign9loc = sign.getLocation();
    52. if (sign.getLine(1) != null) sign9text = sign.getLine(1);
    53. if (sign.getLine(2) != null) sign9item = Integer.parseInt(sign.getLine(2));
    54. }

    Wouldn't it just save all aviable floors ONCE and then it's never able to be set again? I think so :/
     
  2. Offline

    CubieX

    Your code screams for an overhaul with an object oriented approach.
    Why do you use a cascaded HashMap-Structure instead of a class that holds all necessary information?
    Why do you copy identical code for each sign instead of using a list of appropriate objects that hold all that information?
    Like a list or a class?

    Also, you should not predefine a certain number of floor signs.
    It seems as you are trying to make an "Elevator" system to change floors.
    So you could use a [Lift up] and [Lift down] written on the sign to determine which direction you are going to teleport.
    (similar to FalseBooks or CraftBooks "lift" system)
    This way you only need to read the text of the clicked sign and then check above or below this sign for a matching floor sign.
    Or do you want to access all floors directly?
    Perharps I don't fully understand your plugins idea, but your code can surely be improved to be much more compact and generic.

    Your last question: There is not enough code to verify that. The whole method would be needed.
     
  3. Offline

    PreFiXAUT

    CubieX
    Basicly I'm not a pro in creating plugins/java, and there are still so many things that I didn't even know about.
    I saved all the data in HashMaps because it is the once thing I kinda understand. I don't even know how to save all data in a class file.
    Nah, not allways identical but anyway right now.

    Yeah I wan't to create an Elevator System, which is opening an Inventory when there is Sign1 with the tag and above is Sign2 also with the Tag you should be able to teleport to any Sign you want.
    I wanted to try it as good as I can, but now I'm stuck (checking the Signs if signs are one floor up/down).

    It's basicly a part of the SignClickListener. But that isn't that important because I guess I need to recode everything :/
     
Thread Status:
Not open for further replies.

Share This Page