Turn sign string into int???

Discussion in 'Plugin Development' started by ksbdude, Jan 20, 2014.

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

    ksbdude

    I have this bit of code I made for my custom minigame join signs.
    The 3rd line is going to have the arena number in it on the sign.
    However a sign could have text in that line also so eclipse wants me to make it a string which wont work for what i am doing.
    How can i turn a string which has only a number in it into an int??
    Code:java
    1. public void onInteract(PlayerInteractEvent e) {
    2. Sign s = (Sign) e.getClickedBlock().getState();
    3. Player p = e.getPlayer();
    4. if (s.getType() == Material.WALL_SIGN || s.getType() == Material.SIGN_POST) {
    5. if (s.getLine(0).equalsIgnoreCase("§4Arena PVP")) {
    6. if (s.getLine(1).equalsIgnoreCase("§bClick to Join")) {
    7. p.sendMessage("Welcome!");
    8. int arena = s.getLine(2);
    9. ArenaManager.getManager().addPlayer(p, s.getLine(2));
    10. }
    11. }
    12. }
    13. }
     
  2. Offline

    xboxnolifes

    Code:java
    1. Integer.parseInt("String goes here")
    2. //You can put a variable as well (obv)
     
  3. Offline

    EnderTroll68

    Replace:
    Code:java
    1. int arena = s.getLine(2)

    With:
    Code:java
    1. try {
    2. int arena = Integer.parseInt(s.getLine(2));
    3. // the try catch prevents errors if what is on
    4. // the third line is NOT an int
    5. }
     
Thread Status:
Not open for further replies.

Share This Page