Solved Sign problems.

Discussion in 'Plugin Development' started by kreashenz, Sep 14, 2013.

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

    kreashenz

    Hey everyone. I'm getting a little issue using signs and a list trying to check if a line equals one of the strings in the list.

    So I'm using
    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent e){
    3. Player p = e.getPlayer();
    4. String[] lines = e.getLines();
    5. if(lines[0].equalsIgnoreCase("[CreditShop]")){
    6. if (kits.contains(lines[1].toLowerCase())) {
    7. if (isInt(lines[2])) {
    8. e.setLine(0, "§1[CreditShop]");
    9. e.setLine(1, "§f" + StringUtils.capitalize(lines[1]));
    10. e.setLine(2, "§2$" + Integer.parseInt(lines[2]));
    11. } else {
    12. e.getBlock().breakNaturally();
    13. Functions.tell(p, "§cThe price (line 3) must be an number!");
    14. }
    15. } else {
    16. e.getBlock().breakNaturally();
    17. Functions.tell(p, "§cThat kit wasn't found!");
    18. }
    19. }
    20. }

    And the sign is constantly breaking saying "That kit wasn't found!", stated in line 17. Is this happening because I'm not adding the strings to the list? I don't know. I'm using an initialization block to add the strings to the list.
    My whole class looks like
    Code:java
    1. import java.util.ArrayList;
    2. import java.util.List;
    3.  
    4. import me.kreashenz.strayyakits.StrayyaKits;
    5. import me.kreashenz.strayyakits.kits.Kit;
    6. import me.kreashenz.strayyakits.util.Functions;
    7. import me.kreashenz.strayyakits.util.PManager;
    8.  
    9. import org.apache.commons.lang.StringUtils;
    10. import org.bukkit.Location;
    11. import org.bukkit.block.Block;
    12. import org.bukkit.block.Sign;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.block.SignChangeEvent;
    17. import org.bukkit.event.player.PlayerInteractEvent;
    18.  
    19. public class Signs implements Listener {
    20.  
    21. private List<String> kits = new ArrayList<String>();
    22.  
    23. {
    24. for(Kit kits : Kit.values())this.kits.add(kits.getName());
    25. }
    26.  
    27. @EventHandler
    28. public void onSignClick(PlayerInteractEvent e){
    29. Player p = e.getPlayer();
    30. PManager pm = new PManager(p);
    31. if(e.getClickedBlock() != null){
    32. Block b = e.getClickedBlock();
    33. if(b.getState() instanceof Sign){
    34. Sign sign = (Sign)b.getState();
    35. String[] lines = sign.getLines();
    36. if(lines[0].equalsIgnoreCase("Click me to go") && lines[1].equalsIgnoreCase("to the second") && lines[2].equalsIgnoreCase("floor")){
    37. Location loc = p.getLocation();
    38. loc.setY(loc.getY() -3);
    39. p.teleport(loc);
    40. } else if(lines[0].equalsIgnoreCase("§1[CreditShop]")){
    41. for(Kit kit : Kit.values())if(lines[1].equalsIgnoreCase("§f" + kit.getName())){
    42. String l2 = lines[2].replace("§2$", "");
    43. if(isInt(l2)){
    44. Double d = Double.parseDouble(l2);
    45. if(StrayyaKits.getInstance().econ.getBalance(p.getName()) >= d){
    46. Kit a = Kit.getByName(lines[1]);
    47. pm.giveKit(a);
    48. Functions.tell(p, "§7You successfully bought the §6" + a.getName() + " §7kit for §6" + lines[2]);
    49. } else Functions.tell(p, "§cYou can't afford that. You need §6" + (d - StrayyaKits.getInstance().econ.getBalance(p.getName()) + " §cmore credits!"));
    50. }
    51. }
    52. }
    53. }
    54. }
    55. }
    56.  
    57. @EventHandler
    58. public void onSignChange(SignChangeEvent e){
    59. Player p = e.getPlayer();
    60. String[] lines = e.getLines();
    61. if(lines[0].equalsIgnoreCase("[CreditShop]")){
    62. if (kits.contains(lines[1].toLowerCase())) {
    63. if (isInt(lines[2])) {
    64. e.setLine(0, "§1[CreditShop]");
    65. e.setLine(1, "§f" + StringUtils.capitalize(lines[1]));
    66. e.setLine(2, "§2$" + Integer.parseInt(lines[2]));
    67. } else {
    68. e.getBlock().breakNaturally();
    69. Functions.tell(p, "§cThe price (line 3) must be an number!");
    70. }
    71. } else {
    72. e.getBlock().breakNaturally();
    73. Functions.tell(p, "§cThat kit wasn't found!");
    74. }
    75. }
    76. }
    77.  
    78. private boolean isInt(String d){
    79. try {
    80. Integer.parseInt(d);
    81. return true;
    82. return false;
    83. }
    84. }
    85.  
    86. }

    I've asked Rocoty and he said he couldn't find anything wrong with it ( and also kept doing :' ). So my question is, what am I doing wrong and can someone help me?

    [EDIT] [Solved] Had to put the enum values into the list in lowercase letters.
     
  2. Offline

    Techy4198

    what is in the kits list?
     
  3. Offline

    kreashenz

    Techy4198 I've printed it out. It's putting each of the strings into the list, so that's why I posted on here. I have no clue what's happening.
     
  4. Offline

    Techy4198

    kreashenz "...each of the strings..." ???? each of what strings?
     
Thread Status:
Not open for further replies.

Share This Page