Solved Giving kits via signs?

Discussion in 'Plugin Development' started by kreashenz, Apr 8, 2013.

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

    kreashenz

    I'm currently rewriting my Kreas-Kit plugin, and I am adding in signs, for the use of simple gaining of kits and other things, but I can't seem to get it to give the kit, because when I type the kit, it says both my error messages.
    [​IMG]
    I can't get it, I have been trying for atleast the past 5 hours, but I keep getting it to do this.. Here's the code
    Code:java
    1. package me.kreashenz.kitpvp;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.block.Sign;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.block.SignChangeEvent;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.inventory.ItemStack;
    12.  
    13. public class Signs implements Listener {
    14.  
    15. public KitPvP plugin;
    16. public Signs(KitPvP plugin){this.plugin=plugin;}
    17.  
    18. @EventHandler
    19. public void onPlayerClickSign(PlayerInteractEvent e) {
    20. Player p = e.getPlayer();
    21. if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock() != null)
    22. if(e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST) {
    23. Sign s = (Sign)e.getClickedBlock().getState();
    24. String[] lines = s.getLines();
    25. if (lines.length > 1 && lines[0].equalsIgnoreCase("§1[Kreas-Kit]")){
    26. if(p.hasPermission("kitpvp.signs")){
    27. if(lines[1].equalsIgnoreCase("Full") || lines[1].equalsIgnoreCase("Soups") || (lines[1].equalsIgnoreCase("FullSoup")) ||
    28. lines[1].equalsIgnoreCase("Refill")) {
    29. if (!p.hasPermission("kitpvp.refill")) {
    30. p.sendMessage("§cYou do not have permission to refill.");
    31. return;
    32. }
    33. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    34. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    35. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    36. }
    37. }
    38. }
    39. }
    40. }
    41. @EventHandler
    42. public void onSignEdit(SignChangeEvent e){
    43. String[] lines = e.getLines();
    44. Player p = e.getPlayer();
    45. if (lines.length > 1 && lines[0].equalsIgnoreCase("[KreasKit]")) {
    46. if (p.hasPermission("kitpvp.signs.refill")) {
    47. if (lines[1].equalsIgnoreCase("Full")
    48. || lines[1].equalsIgnoreCase("Soups")
    49. || lines[1].equalsIgnoreCase("FullSoup")
    50. || lines[1].equalsIgnoreCase("Refill")) {
    51. e.setLine(0, "§1[Kreas-Kit]");
    52. e.setLine(1, "Soups");
    53. p.sendMessage("§aSuccessfully created sign!");
    54. } else {
    55. e.getBlock().breakNaturally();
    56. p.sendMessage("§cCouldn't find the sign you wanted to create, please try again!");
    57. }
    58. } else {
    59. e.getBlock().breakNaturally();
    60. p.sendMessage("§cYou do not have permission to create signs.");
    61. }
    62. }
    63. if(lines.length > 1 && lines[0].equalsIgnoreCase("[KreasKit]")){
    64. if(p.hasPermission("kitpvp.signs.kits")){
    65. if(plugin.getConfig().contains("Kits." + lines[1])){
    66. e.setLine(0, "§1[Kreas-Kit]");
    67. e.setLine(1, lines[1].toUpperCase());
    68. } else {
    69. e.getBlock().breakNaturally();
    70. p.sendMessage("§cCouldn't find that kit, please try again.");
    71. }
    72. } else {
    73. e.getBlock().breakNaturally();
    74. p.sendMessage("§cYou do not have permission to create signs.");
    75. }
    76. }
    77. }
    78. }
    79.  

    Any sort of examples would be much appreciated, or any sources that would be doing the same thing. Thanks!!
     
  2. Offline

    chasechocolate

    If you only want it to send one message, just add return so it won't do any checks after that.
     
  3. Offline

    kreashenz

    chasechocolate .. That's not really what I was asking to do, I was asking why it wasn't giving the kits, and why it was breaking on placement. I kinda just added in the full Signs.java class, so maybe re-read it or something.
     
  4. Offline

    TheUpdater

    well line 0 is the top one
    it goes like this
    0 [sup]
    1 [lol]
    2 10/11
    3 no

    hope it helps lol...
     
  5. Offline

    kreashenz

    TheUpdater I know that, I didn't really need to get told, but thanks for the input :)

    Bumpity Bump..
    I was working with the code for about 20 minutes last night, before I got off, edited and asked someone if he could help me with this.. He helped as much as he could, and now, as I place my sign, even if the kit doesn't exist, it'll still place the sign, no matter whats under it. Here's the new code.
    Code:java
    1. package me.kreashenz.kitpvp;
    2.  
    3. import java.util.List;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Sign;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.block.SignChangeEvent;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.inventory.ItemStack;
    14.  
    15. public class Signs implements Listener {
    16.  
    17. public KitPvP plugin;
    18. public Signs(KitPvP plugin){this.plugin=plugin;}
    19.  
    20. @EventHandler
    21. public void onPlayerClickSign(PlayerInteractEvent e) {
    22. Player p = e.getPlayer();
    23. if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock() != null)
    24. if(e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST) {
    25. Sign s = (Sign)e.getClickedBlock().getState();
    26. String[] lines = s.getLines();
    27. if (lines.length > 1 && lines[0].equalsIgnoreCase("§1[Kreas-Kit]")){
    28. if(p.hasPermission("kitpvp.signs")){
    29. if(lines[1].equalsIgnoreCase("Full") || lines[1].equalsIgnoreCase("Soups") || (lines[1].equalsIgnoreCase("FullSoup")) ||
    30. lines[1].equalsIgnoreCase("Refill")) {
    31. if (!p.hasPermission("kitpvp.refill")) {
    32. p.sendMessage("§cYou do not have permission to refill.");
    33. return;
    34. }
    35. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    36. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    37. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    38. }
    39. }
    40. }
    41. }
    42. }
    43. @EventHandler
    44. public void onSignEdit(SignChangeEvent e){
    45. String[] lines = e.getLines();
    46. Player p = e.getPlayer();
    47. if (lines.length > 1 && lines[0].equalsIgnoreCase("[KreasKit]")) {
    48. if (p.hasPermission("kitpvp.signs.refill")) {
    49. if (lines[1].equalsIgnoreCase("Full")
    50. || lines[1].equalsIgnoreCase("Soups")
    51. || lines[1].equalsIgnoreCase("FullSoup")
    52. || lines[1].equalsIgnoreCase("Refill")
    53. && !(plugin.getConfig().getStringList("Kits." + lines[1]) != null)) {
    54. e.setLine(0, "§1[Kreas-Kit]");
    55. e.setLine(1, "Soups");
    56. p.sendMessage("§aSuccessfully created sign!");
    57. } else if(plugin.getConfig().getStringList("Kits." + lines[1]) != null){
    58. e.setLine(0, "§1[Kreas-Kit]");
    59. e.setLine(1, lines[1]);
    60. }
    61. } else {
    62. e.getBlock().breakNaturally();
    63. p.sendMessage("§cYou do not have permission to create signs.");
    64. }
    65. }
    66. List <String> allkits = plugin.getConfig().getStringList("Kits.");
    67. if(lines.length > 1 && lines[0].equalsIgnoreCase("[KreasKit]")){
    68. if(p.hasPermission("kitpvp.signs.kits")){
    69. if(allkits.contains(lines[1])){
    70. e.setLine(0, "§1[Kreas-Kit]");
    71. e.setLine(1, lines[1]);
    72. } else {
    73. e.getBlock().breakNaturally();
    74. p.sendMessage("§cCouldn't find that kit, please try again.");
    75. }
    76. } else {
    77. e.getBlock().breakNaturally();
    78. p.sendMessage("§cYou do not have permission to create signs.");
    79. }
    80. }
    81. }
    82. }
    83.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    KingFaris10

    Hey, this is the worst way to do this. There's many other better ways to make sign kits. I'm sorry but I'm not going to post an improved version because I'm really new to the "code" feature in Bukkit Forums and I have no idea how to use it.
     
  7. Offline

    kreashenz

    KingFaris10 What do you mean, the "code" feature, it's fairly easy.
     
  8. Offline

    KingFaris10

    The "code" in square brackets to paste code etc.
    For me it never puts spaces and it has all my code in one line. I have to use the P (html code) to add new lines
     
  9. Offline

    kreashenz

    KingFaris10 I don't use the indents, I CTRL + F and Find TAB , replace with 4 spaces.. Works fine :)
     
  10. Offline

    kreashenz

    #Another shameful bump :(
    But I still REALLY need this. I have kind of fixed a few little things, but I can't get it to give me the kit, it sends NullPointerExceptions on the PyroKit(p); And I don't know how to fix that. I have read the Troubleshoot your own plugins, but that didn't really help. Anyone PLEASE give me an answer, it would be greatly appreciated!
    What it does, is doesn't break the sign if the lines[1] is wrong, but it doesn't set it to the &1[Kreas-Kit] which is good, but when I have got it set correctly, it sends the NPE.
    Code:java
    1. package me.kreashenz.kitpvp;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.block.SignChangeEvent;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15.  
    16. public class Signs implements Listener {
    17.  
    18. public KitPvP plugin;
    19. public Kits kits;
    20. public Signs(KitPvP plugin, Kits kits) {
    21. this.plugin = plugin;
    22. this.kits = kits;
    23. }
    24. @EventHandler
    25. public void onPlayerClickSign(PlayerInteractEvent e) {
    26. Player p = e.getPlayer();
    27. if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock() != null)
    28. if (e.getClickedBlock().getType() == Material.WALL_SIGN
    29. || e.getClickedBlock().getType() == Material.SIGN_POST) {
    30. Sign s = (Sign) e.getClickedBlock().getState();
    31. String[] lines = s.getLines();
    32. if (lines.length > 1 && lines[0].equalsIgnoreCase("§1[Kreas-Kit]")) {
    33. if (p.hasPermission("kitpvp.signs")) {
    34. if (lines[1].equalsIgnoreCase("Full") || lines[1].equalsIgnoreCase("Soups")
    35. || (lines[1].equalsIgnoreCase("FullSoup"))
    36. || lines[1].equalsIgnoreCase("Refill")) {
    37. if (!p.hasPermission("kitpvp.refill")) {
    38. p.sendMessage("§cYou do not have permission to refill.");
    39. return;
    40. }
    41. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    42. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    43. p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    44. }
    45. if(lines[1].equalsIgnoreCase("Pyro")){
    46. if(!p.hasPermission("kitpvp.pyro")){
    47. p.sendMessage("§cYou do not have permission to use the Pyro kit.");
    48. return;
    49. }
    50. kits.PyroKit(p);
    51. }
    52. if(lines[1].equalsIgnoreCase("PvP")){
    53. if(!p.hasPermission("kitpvp.pvp")){
    54. p.sendMessage("§cYou do not have permission to use the PvP kit.");
    55. return;
    56. }
    57. kits.PvPKit(p);
    58. }
    59. if(lines[1].equalsIgnoreCase("Tank")){
    60. if(!p.hasPermission("kitpvp.tank")){
    61. p.sendMessage("§cYou do not have permission to use the Tank kit.");
    62. return;
    63. }
    64. kits.TankKit(p);
    65. }
    66. if(lines[1].equalsIgnoreCase("medic")){
    67. if(!p.hasPermission("kitpvp.medic")){
    68. p.sendMessage("§cYou do not have permission to use the Medic kit.");
    69. return;
    70. }
    71. kits.MedicKit(p);
    72. }
    73. if(lines[1].equalsIgnoreCase("archer")){
    74. if(!p.hasPermission("kitpvp.archer")){
    75. p.sendMessage("§cYou do not have permission to use the Archer kit.");
    76. return;
    77. }
    78. kits.ArcherKit(p);
    79. }
    80. } else p.sendMessage("§cYou don't have permission to use signs.");
    81. }
    82. }
    83. }
    84.  
    85. @EventHandler
    86. public void onSignEdit(SignChangeEvent e) {
    87. String[] lines = e.getLines();
    88. Player p = e.getPlayer();
    89. boolean breakSign = false;
    90. List<String> errorMessages = new ArrayList<String>();
    91. if (lines.length > 1 && lines[0].equalsIgnoreCase("[KreasKit]")) {
    92. if (p.hasPermission("kitpvp.signs.refill")) {
    93. if (lines[1].equalsIgnoreCase("Full") || lines[1].equalsIgnoreCase("Soups")
    94. || lines[1].equalsIgnoreCase("FullSoup")
    95. || lines[1].equalsIgnoreCase("Refill")) {
    96. e.setLine(0, "§1[Kreas-Kit]");
    97. e.setLine(1, "Soups");
    98. p.sendMessage("§aSuccessfully created sign!");
    99. }
    100. } else {
    101. errorMessages.add("§cYou do not have permission to create signs.");
    102. breakSign = true;
    103. }
    104. if (p.hasPermission("kitpvp.signs.kits.pyro")){
    105. if(lines[1].equalsIgnoreCase("Pyro")){
    106. e.setLine(0, "§1[Kreas-Kit]");
    107. e.setLine(1, "Pyro");
    108. p.sendMessage("§aSuccessfully created sign!");
    109. }
    110. } else {
    111. errorMessages.add("§cYou do not have permission to create signs.");
    112. breakSign = true;
    113. }
    114. if(p.hasPermission("kitpvp.signs.kits.archer")){
    115. if(lines[1].equalsIgnoreCase("Archer")){
    116. e.setLine(0, "§1[Kreas-Kit]");
    117. e.setLine(1, "Archer");
    118. p.sendMessage("§aSuccessfully created sign!");
    119. }
    120. } else {
    121. errorMessages.add("§cYou do not have permission to create signs.");
    122. breakSign = true;
    123. }
    124. if(p.hasPermission("kitpvp.signs.kits.pvp")){
    125. if(lines[1].equalsIgnoreCase("PvP")){
    126. e.setLine(0, "§1[Kreas-Kit]");
    127. e.setLine(1, "PvP");
    128. p.sendMessage("§aSuccessfully created sign!");
    129. }
    130. } else {
    131. errorMessages.add("§cYou do not have permission to create signs.");
    132. breakSign = true;
    133. }
    134. if(p.hasPermission("kitpvp.signs.kits.tank")){
    135. if(lines[1].equalsIgnoreCase("Tank")){
    136. e.setLine(0, "§1[Kreas-Kit]");
    137. e.setLine(1, "Tank");
    138. p.sendMessage("§aSuccessfully created sign!");
    139. }
    140. } else {
    141. errorMessages.add("§cYou do not have permission to create signs.");
    142. breakSign = true;
    143. }
    144. if(p.hasPermission("kitpvp.signs.kits.medic")){
    145. if(lines[1].equalsIgnoreCase("Medic")){
    146. e.setLine(0, "§1[Kreas-Kit]");
    147. e.setLine(1, "Medic");
    148. p.sendMessage("§aSuccessfully created sign!");
    149. }
    150. } else {
    151. errorMessages.add("§cYou do not have permission to create signs.");
    152. breakSign = true;
    153. }
    154. if (breakSign) {
    155. e.getBlock().breakNaturally();
    156. for (String errorMessage : errorMessages)
    157. p.sendMessage(errorMessage);
    158. }
    159. }
    160. }
    161. }
     
Thread Status:
Not open for further replies.

Share This Page