Solved Annoying bukkit error + leather armour coloring, please help!

Discussion in 'Plugin Development' started by FirecatHD, Nov 13, 2013.

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

    FirecatHD

    Ok, i am getting an annoying error in my plugin, i am really new (this is my first day coding, ever) so i wonder if i can get some tips too?

    It says "Syntax error, insert "}" to complete ClassBody" on the last }, but i have clearly placed it :confused:
    The error came after i added permissions, so does anyone have any tips for me there?
    I really want to solve this!

    Next problem is to color leather armour with RGB or HEX colorcodes, how can i do this?
    and where do i place the code? If someone can tell me, i would be really grateful!

    Source code:
    Code:java
    1. package me.FirecatHD.TBS_PvP;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Color;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.enchantments.Enchantment;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.inventory.PlayerInventory;
    12. import org.bukkit.inventory.meta.LeatherArmorMeta;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.potion.PotionEffect;
    15. import org.bukkit.potion.PotionEffectType;
    16.  
    17. public class Kits extends JavaPlugin {
    18.  
    19. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    20. if (!(sender instanceof Player)) {
    21. sender.sendMessage(ChatColor.RED + "Only players can get kits!");
    22. return true;
    23. }
    24.  
    25. Player p = (Player) sender;
    26. PlayerInventory pi = p.getInventory();
    27.  
    28. if (cmd.getName().equalsIgnoreCase("basic")) {
    29.  
    30. pi.clear();
    31. pi.setArmorContents(null);
    32.  
    33. for(PotionEffect effect : p.getActivePotionEffects())
    34. {
    35. p.removePotionEffect(effect.getType());
    36. }
    37.  
    38. ItemStack Sword = new ItemStack(Material.DIAMOND_SWORD, 1);
    39. Sword.addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    40. Sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1);
    41. pi.addItem(Sword);
    42.  
    43. ItemStack Bow = new ItemStack(Material.BOW, 1);
    44. Bow.addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    45. Bow.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1000);
    46. Bow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 1);
    47. pi.addItem(Bow);
    48.  
    49. pi.setHelmet(new ItemStack(Material.IRON_HELMET));
    50. pi.setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
    51. pi.setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    52. pi.setBoots(new ItemStack(Material.IRON_BOOTS));
    53.  
    54. pi.getHelmet().addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    55. pi.getChestplate().addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    56. pi.getLeggings().addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    57. pi.getBoots().addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    58.  
    59. pi.getHelmet().addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    60. pi.getChestplate().addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    61. pi.getLeggings().addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    62. pi.getBoots().addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    63.  
    64. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    65. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    66. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    67. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    68. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    69. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    70. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    71. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    72. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    73. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    74. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    75. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    76. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    77. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    78. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    79. pi.addItem(new ItemStack(Material.ARROW , 1));
    80. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    81. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    82. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    83. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    84. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    85. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    86. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    87. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    88. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    89. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    90. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    91. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    92. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    93. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    94. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    95. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    96. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    97. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    98.  
    99. p.sendMessage(ChatColor.DARK_BLUE + "[TBS PvP]: " + ChatColor.GREEN + "You equipped " + ChatColor.BLUE + "Basic! " + ChatColor.GRAY + "Its balanced, but yet strong!");
    100. }
    101.  
    102. return true;
    103.  
    104. {
    105.  
    106. {
    107.  
    108.  
    109. if (cmd.getName().equalsIgnoreCase("setmotd")) {
    110. if (!sender.hasPermission("motd.set")) {
    111. sender.sendMessage(ChatColor.RED + "You are not permitted to do this!");
    112. return true;
    113.  
    114. }
    115.  
    116. if (cmd.getName().equalsIgnoreCase("derpy")) {
    117.  
    118.  
    119. pi.clear();
    120. pi.setArmorContents(null);
    121.  
    122. for(PotionEffect effect : p.getActivePotionEffects())
    123. {
    124. p.removePotionEffect(effect.getType());
    125. }
    126.  
    127. //Potion effects
    128.  
    129. p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 1000000, 0));
    130. p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 1000000, 2));
    131. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * 1000000, 1));
    132. p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20 * 1000000, 1));
    133.  
    134. //Enchantments
    135.  
    136. ItemStack Sword = new ItemStack(Material.WHEAT, 1);
    137. Sword.addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    138. Sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 3);
    139. pi.addItem(Sword);
    140.  
    141. //Armour
    142.  
    143. pi.setHelmet(new ItemStack(Material.LEATHER_HELMET));
    144. pi.setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
    145. pi.setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
    146. pi.setBoots(new ItemStack(Material.LEATHER_BOOTS));
    147.  
    148. //Armour enchantments
    149.  
    150. pi.getHelmet().addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    151. pi.getChestplate().addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    152. pi.getLeggings().addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    153. pi.getBoots().addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    154.  
    155. pi.getHelmet().addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    156. pi.getChestplate().addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    157. pi.getLeggings().addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    158. pi.getBoots().addUnsafeEnchantment(Enchantment.DURABILITY, 1000);
    159.  
    160. //Leather armour colors
    161. pi.getHelmet();
    162. ItemStack lhelmet = new ItemStack(Material.LEATHER_HELMET, 1);
    163. LeatherArmorMeta lam = (LeatherArmorMeta)lhelmet.getItemMeta();
    164. lam.setColor(Color.fromRGB(255, 248, 148));
    165. lhelmet.setItemMeta(lam);
    166.  
    167. //Items
    168.  
    169. pi.addItem(new ItemStack(Material.CAKE , 1));
    170. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    171. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    172. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    173. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    174. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    175. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    176. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    177. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    178. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    179. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    180. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    181. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    182. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    183. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    184. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    185. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    186. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    187. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    188. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    189. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    190. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    191. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    192. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    193. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    194. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    195. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    196. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    197. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    198. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    199. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    200. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    201. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    202. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    203. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    204.  
    205. //On give message
    206.  
    207. p.sendMessage(ChatColor.DARK_BLUE + "[TBS PvP]: " + ChatColor.YELLOW + "You equipped " + ChatColor.LIGHT_PURPLE + "Derpy! " + ChatColor.YELLOW + "Your left eye rolls off in another direction while you prepare for battle!");
    208.  
    209.  
    210.  
    211. return true;
    212. }
    213. }
    214. }
    215. }
    216. }
    217.  


    Thanks in advance :) !
     
  2. Offline

    Seadragon91

  3. Offline

    FirecatHD

    Thanks, but what did i do wrong? :oops:

    Anyone that know how to fix the syntax problem please tell me, i need to know because i have the problem again.

    So i need to fix it myself :3

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

    MisterErwin

    FirecatHD : You need to insert a "}" at the end of your file...

    I guess you added the if for the permissions, but forgot to add the ending curly break ;)
     
  5. Offline

    sgavster

    Because.. ​
    Code:java
    1. }
    2.  
    3. return true;
    4.  
    5. {
    6.  
    7. {

    ???
    The 2 bottom ones should be facing the other way.
    also, after the first command use
    else if(cmd.blahblah)) ect
    and, an easy way to add soup

    Code:
    for(int i = 0; i < AMOUNT_OF_SOUP_YOU_WANT; i++) {
    pi.addItem(new ItemStack(Material.MUSHROOM_SOUP , 1));
    }
     
    FirecatHD likes this.
  6. Offline

    FirecatHD

    sgavster and MisterErwin

    When i do what you said sgavster (place two last curly breaks the opposite direction) i get a lot of errors :(
    Btw thanks for the soup code :)

    And MisterErwin, i dont really understand what you mean, as i can see i have placed a curly break where you told me?
    Anyways i hope to get a solution!

    Thanks.
     
  7. Offline

    sgavster

    FirecatHD .. learn how to format, in eclipse do this:
    ctrl + a + i
    or
    ctrl shift f
     
    FirecatHD likes this.
  8. Offline

    Zarko

    offtopic"a bit":you went from 0 to that? Its a little bit weird :C
     
  9. Offline

    FirecatHD

    sgavster I have managed to get the perms running and i think i understand what you meant :) So it is working for now. Also can i ask you if i get a problem in the future?

    Zarko I thought someone would say that, but i can tell you i HAVE written the code myself, that is why it is messy :oops:
    I take it as a compliment :D

    Thanks!

    Now i just need a method to dye the leather armour on the Derpy kit in any color i want (RGB or HEX) so if anyone knows, please tell me!

    Thanks.

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

    sgavster

    FirecatHD
    PHP:
    ItemStack h = new ItemStack(Material.LEATHER_HELMET);
    LeatherArmorMeta hm = (LeatherArmorMetah.getItemMeta();
    hm.setColor(Color.COLOR);
    h.setItemMeta(hm);
     
    //TO GIVE:
     
    player.getInventory().addItem(h);
    And sure. You can ask me.
     
  11. Offline

    FirecatHD

    sgavster

    Thanks, but do you know how to like add the RGB (red green and blue) so i can get whatever color i want?
    Anyways the code you showed me already helps too :)

    Thanks.
     
  12. Offline

    sgavster

  13. Offline

    FirecatHD

    SkillSam

    Ohh thank you so much!
    I really appriciate people like you and the other that have helped me :)

    I did learn some neat tricks from the code that you gave me, they will definitly come in handy :D
    I cant belive that you acually rewrote the wole thing!

    Anyways i will ask you the same as i asked sgavster if it is ok if i tag you if i get an error in the future, so you can see it and maybe help me.

    I have some more questions so i will throw them in here as i come across them.

    Thanks, again.

    Ok i have a question sgavster and SkillSam (And anyone else that knows and answer)

    How can i restrict a plugin or code to ONE world?

    Like:

    if (!(getServer() getWorld() = "worldname");
    return true;

    Is there a method for this? I need to know in order to proceed with my plugin :oops:

    Thanks. :)

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

    xTrollxDudex

    FirecatHD
    PHP:
    //Line 28
    if(!p.getWorld().getName().equals(/*string name goes here*/)) {
        
    p.sendMessage("Cannot execute on this world!");
        return 
    true;
    }
     
  15. Offline

    FirecatHD

Thread Status:
Not open for further replies.

Share This Page