Solved Method Causing Heaps of Errors. x_x

Discussion in 'Plugin Development' started by TheHandfish, May 1, 2014.

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

    TheHandfish

    Hey, in my Move event, I have this method that, when used, is supposed to return the player's position. It checks for nearby signs with line 1 as "#" and line 2 as any given number, then returns it. Depending on how high that number is, that is your position. When you cross a lap, it adds however many markers you have in the level to the number of a sign you are currently near. The equation is something like:

    Answer = Sign Number + Laps * Marker count.

    Here are the errors I'm getting:

    Here is the code I'm using.
    Code:javascript
    1. public static int evalPlace(Player p)
    2. {
    3. Location playerLoc = p.getLocation();
    4. int pX = playerLoc.getBlockX();
    5. int pY = playerLoc.getBlockY();
    6. int pZ = playerLoc.getBlockZ();
    7.  
    8. for (int x = -7; x <= 7; x ++)
    9. {
    10. for (int y = -7; y <= 7; y ++)
    11. {
    12. for (int z = -7; z <= 7; z ++)
    13. {
    14. Block b = p.getWorld().getBlockAt((int)pX+x, (int)pY+y, (int)pZ+z);
    15. if(b.getType() == Material.SIGN || b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN)
    16. {
    17. BlockState state = b.getState();
    18. Sign sign = (Sign)state;
    19. String signline1 = sign.getLine(1);
    20. int signline2 = Integer.parseInt(sign.getLine(1));
    21. if(signline1.equals("#"))
    22. {
    23. int markers = plugin.getConfig().getInt("Path.Editor.Markers");
    24. int pllap = p.getMetadata("playerLap").get(0).asInt();
    25.  
    26. if(pllap > 1)
    27. {
    28. return signline2 + pllap * markers;
    29. }
    30. else
    31. {
    32. return signline2;
    33. }
    34. }
    35. else
    36. {
    37. return 0;
    38. }
    39. }
    40. }
    41. }
    42. }
    43. return 0;
    44. }

    Thanks much!
     
  2. Offline

    Necrodoom

    You convert the line without checking if its actually an int. Add a try catch or using check and drop out of function if not integer.
    Also, it looks like the specific problem is caused by an invisible symbol. Are you using Mac? If yes, that is generating it though arrow keys.
     
  3. Offline

    TheHandfish

    Necrodoom:

    I am using a Mac, yes. I did what you said, and sure enough, it's saying that the sign numbers aren't integers. How do I get rid of the invisible symbol? I want there to just be a number. Hopefully this doesn't mean I'll have to go through and modify all 328 markers. :s

    Necrodoom: Bumped. .-.

    Anyone:

    Bumped again. Really need help with how to convert this to a proper int... ._.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    Aqua

    int signline2 = 0;
    try {
    signline2 = Integer.parseInt(sign.getLine(1));
    } catch (Exception e) {
    return -1; //Line is not a number
    }

    TheHandfish
    Forgot tahg

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    TheHandfish

    Aqua: Thanks, I already did. However, I fixed the problem by simply using the replace() method to replace the unknown character. :)
     
Thread Status:
Not open for further replies.

Share This Page