Solved A Quick Question

Discussion in 'Plugin Development' started by FuZioN720, May 24, 2013.

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

    FuZioN720

    if you want to use a if statement to say for example, if (book.getTitle() == "Stats"). If the book has a Title of ChatColor.DARK_PURPLE do i need to use if (bm.getTitle() == ChatColor.DARK_PURPLE + "Stats"). Or can i just use if (bm.getTitle() == "Stats")
     
  2. Offline

    Tzeentchful

    FuZioN720
    None of the above.
    You can't use the '==' opperatoe when comapign strings. Because a string is not a pritave it's an object and because of that you must use..
    Code:java
    1. .equals("a string");

    And actually answering your question. You can strip all colour codes fomr a string like so.
    Code:java
    1. ChatColor.stripColor(...);

    Then you can compare the string without having to worry about colour codes.
     
    TheGreenGamerHD likes this.
  3. Offline

    FuZioN720

    Tzeentchful ok so my end product should be like if(book.getTilte().equals(ChatColor.stripColor(DARK_PURPLE) + "Stats"))?
     
  4. Offline

    Tzeentchful

    FuZioN720
    Almost.
    The ChatColor.stripColor(...) method strip the colour from a string so you should have it like this.
    Code:java
    1. if(ChatColor.stripColor(book.getTilte()).equals("Stats")) {
     
    FuZioN720 likes this.
  5. Offline

    FuZioN720

Thread Status:
Not open for further replies.

Share This Page