Solved Armour not showing up

Discussion in 'Plugin Development' started by cfil360, Apr 11, 2014.

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

    cfil360

    I have created a plugin that gives you armour when you click a sign. Everything works fine with no errors, but the armour doesn't show up in the player's inventory. It only shows up once the player moves around their weapon. I don't know if this is a problem with the plugin or code, but there are no errors being thrown whatsoever.
    Main Class
    Code:java
    1. package me.connor.kit;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.util.ArrayList;
    6.  
    7. import net.milkbowl.vault.economy.Economy;
    8. import net.milkbowl.vault.economy.EconomyResponse;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.Material;
    13. import org.bukkit.command.Command;
    14. import org.bukkit.command.CommandSender;
    15. import org.bukkit.configuration.file.FileConfiguration;
    16. import org.bukkit.configuration.file.YamlConfiguration;
    17. import org.bukkit.enchantments.Enchantment;
    18. import org.bukkit.entity.Player;
    19. import org.bukkit.inventory.ItemStack;
    20. import org.bukkit.inventory.PlayerInventory;
    21. import org.bukkit.plugin.RegisteredServiceProvider;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23.  
    24.  
    25. public class Main extends JavaPlugin {
    26.  
    27. public Economy econ = null;
    28. public int kitPrice;
    29. public int seconds;
    30. File kitFile = new File(getDataFolder(), "kits.yml");
    31. FileConfiguration kitFileConfig;
    32. ArrayList<String> enchantments = new ArrayList<String>();
    33. ArrayList<String> enchantmentLevels = new ArrayList<String>();
    34.  
    35. public void onEnable() {
    36. if (!getDataFolder().exists()) {
    37. getDataFolder().mkdir();
    38. }
    39.  
    40. //check to make sure kits.yml exists
    41. if(!kitFile.exists()) {
    42. this.saveResource("kits.yml", false);
    43. }
    44. //load the kit file
    45. loadYamls();
    46.  
    47. //register events
    48. Bukkit.getServer().getPluginManager().registerEvents(new KitListener(this), this);
    49.  
    50. //save the config
    51. this.saveDefaultConfig();
    52.  
    53. //check to see if the economy is enabled and exists
    54. if(isEconomyEnabled()) {
    55. if (!setupEconomy() ) {
    56. getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName())); //notify user why the plugin is disabled
    57. getServer().getPluginManager().disablePlugin(this); //disable the plugin
    58. return;
    59. }
    60. }
    61. }
    62.  
    63. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    64. //make sure that the console can't use kits
    65. if (!(sender instanceof Player)) {
    66. sender.sendMessage(ChatColor.RED + "Only players can get kits!");
    67. return true;
    68. }
    69.  
    70. //define the player once we make sure it is a player
    71. Player p = (Player) sender;
    72. //define the player's inventory
    73. PlayerInventory pi = p.getInventory();
    74.  
    75. if (cmd.getName().equalsIgnoreCase("kit")) {
    76. if(!p.hasPermission("kit.player")) {
    77. p.sendMessage(ChatColor.RED + "You don't have permission to do that!");
    78. return true;
    79. }
    80.  
    81. //output the basic kit command
    82. if(args.length == 0) {
    83. p.sendMessage(ChatColor.RED + "Please specify a kit! Type /kit list for a list of kits.");
    84. return true;
    85. }
    86.  
    87. //output a list of available kits
    88. if(args.length == 1 && args[0].equalsIgnoreCase("list")) {
    89. p.sendMessage(ChatColor.YELLOW + "Available Kits:");
    90. p.sendMessage(ChatColor.YELLOW + "=========================");
    91. for(String s : kitFileConfig.getKeys(true)) {
    92. if(!s.contains(".")) p.sendMessage(ChatColor.YELLOW + s);
    93. }
    94. return true;
    95. }
    96.  
    97. //clears a player's inventory
    98. if(args.length == 1 && args[0].equalsIgnoreCase("clear")) {
    99. pi.clear();
    100. pi.setArmorContents(null);
    101. return true;
    102. }
    103.  
    104. //reloads the kits from the config
    105. if(args.length == 1 && args[0].equalsIgnoreCase("reload")) {
    106. //checks to see if sender has correct permissions
    107. if(!p.hasPermission("Kits.Admin")) {
    108. p.sendMessage(ChatColor.RED + "You don't have permission to do that.");
    109. return true; //return if the player doesn't have permission and notify them
    110. }
    111. this.reloadConfig(); //get the new config
    112. this.saveConfig(); //save the new config
    113. saveYamls(); //save the yaml files
    114.  
    115. //notify sender the kits have been reloaded
    116. p.sendMessage(ChatColor.GREEN + "Kits reloaded!");
    117. return true;
    118. }
    119.  
    120. //check to see if the kit exists or not
    121. if(!isKit(args[0])) {
    122. p.sendMessage(ChatColor.RED + "" + args[0] + " isn't a defined kit!");
    123. return true;
    124. }
    125.  
    126. else if(kitFileConfig.contains(args[0].toUpperCase())) {
    127. try {
    128. if(isEconomyEnabled()) {
    129. //get the cost of the kit from the config
    130. double cost = kitFileConfig.getDouble(args[0].toUpperCase() + ".Price");
    131.  
    132. //withdraw the money
    133. EconomyResponse r = this.econ.withdrawPlayer(p.getName(), cost);
    134. }
    135.  
    136. //clear the player's inventory before giving them items
    137. pi.clear();
    138.  
    139. //define basic enchantment strings and levels to set
    140. String weaponStr;
    141.  
    142. //get the weapon String
    143. String weaponString = getItem(args[0], ".Weapon");
    144.  
    145. //split the weapon String
    146. String[] weaponParts = splitString(weaponString, ",");
    147.  
    148. for(String s : weaponParts) { //cycles through each weapon
    149. String[] weaponPartsString = splitString(s, "#");
    150. //^ split the string into ^
    151. //1)weapon
    152. //2)enchantment
    153. //3)level
    154.  
    155. //define the weapon string from the parts
    156. weaponStr = weaponPartsString[0];
    157.  
    158. //define the itemstack for the weapon
    159. ItemStack weapon = new ItemStack(Material.matchMaterial(weaponStr));
    160.  
    161. if(hasEnchantments(s)) { //tests to see if the weapon should have enchantments
    162. //fill the enchantmentsArray
    163. fillEnchantments(splitString(weaponPartsString[1], "@"));
    164. //fill the enchantmentLevelsArray
    165. fillEnchantmentLevels(splitString(weaponPartsString[2], "@"));
    166. //enchant the weapon
    167. weapon = enchant(weapon);
    168. } //end the test for multiple enchantments
    169.  
    170. pi.addItem(weapon);
    171. } //end the cycling of all weapons
    172.  
    173.  
    174.  
    175.  
    176.  
    177.  
    178. //////////////helmet////////////////
    179.  
    180.  
    181.  
    182.  
    183.  
    184.  
    185.  
    186. // define basic enchantment strings and levels to set
    187. String helmetStr;
    188.  
    189. // get the helmet String
    190. String helmetString = getItem(args[0], ".Helmet");
    191.  
    192. String[] helmetPartsString = splitString(helmetString, "#");
    193. // ^ split the string into ^
    194. // 1)weapon
    195. // 2)enchantment
    196. // 3)level
    197.  
    198. // define the weapon string from the split string
    199. helmetStr = helmetPartsString[0];
    200.  
    201. // define the itemstack for the weapon
    202. ItemStack helmet = new ItemStack(Material.matchMaterial(helmetStr));
    203.  
    204. if (hasEnchantments(helmetString)) { // tests to see if the helmet should have enchantments
    205. // fill the enchantmentsArray
    206. fillEnchantments(splitString(helmetPartsString[1], "@"));
    207.  
    208. // fill the enchantmentLevelsArray
    209. fillEnchantmentLevels(splitString(helmetPartsString[2], "@"));
    210.  
    211. // enchant the helmet
    212. enchant(helmet);
    213.  
    214. } // end the test for multiple enchantments
    215.  
    216. pi.setHelmet(helmet);
    217.  
    218.  
    219.  
    220. //////////////chestplate////////////////
    221.  
    222.  
    223.  
    224.  
    225.  
    226. // define basic enchantment strings and levels to set
    227. String chestplateStr;
    228.  
    229. // get the helmet String
    230. String chesplateString = getItem(args[0], ".Chestplate");
    231.  
    232. String[] chestplatePartsString = splitString(chesplateString, "#");
    233. // ^ split the string into ^
    234. // 1)weapon
    235. // 2)enchantment
    236. // 3)level
    237.  
    238. // define the weapon string from the split string
    239. chestplateStr = chestplatePartsString[0];
    240.  
    241. // define the itemstack for the chestplate
    242. ItemStack chestplate = new ItemStack(Material.matchMaterial(chestplateStr));
    243.  
    244. if (hasEnchantments(chesplateString)) { // tests to see if the chestplate should have enchantments
    245. // fill the enchantmentsArray
    246. fillEnchantments(splitString(chestplatePartsString[1],
    247. "@"));
    248.  
    249. // fill the enchantmentLevelsArray
    250. fillEnchantmentLevels(splitString(chestplatePartsString[2], "@"));
    251.  
    252. // enchant the helmet
    253. enchant(chestplate);
    254.  
    255. } // end the test for multiple enchantments
    256.  
    257. pi.setChestplate(chestplate);
    258.  
    259. // ////////////leggings////////////////
    260.  
    261. // define basic enchantment strings and levels to set
    262. String leggingsStr;
    263.  
    264. // get the leggings String
    265. String leggingsString = getItem(args[0], ".Leggings");
    266.  
    267. String[] leggingsPartsString = splitString(leggingsString, "#");
    268. // ^ split the string into ^
    269. // 1)weapon
    270. // 2)enchantment
    271. // 3)level
    272.  
    273. // define the leggings string from the split string
    274. leggingsStr = leggingsPartsString[0];
    275.  
    276. // define the itemstack for the chestplate
    277. ItemStack leggings = new ItemStack(
    278. Material.matchMaterial(leggingsStr));
    279.  
    280. if (hasEnchantments(leggingsString)) { // tests to see if the leggings should have enchantments
    281. // fill the enchantmentsArray
    282. fillEnchantments(splitString(leggingsPartsString[1], "@"));
    283.  
    284. // fill the enchantmentLevelsArray
    285. fillEnchantmentLevels(splitString(leggingsPartsString[2], "@"));
    286.  
    287. // enchant the leggings
    288. enchant(leggings);
    289.  
    290. } // end the test for multiple enchantments
    291.  
    292. pi.setLeggings(leggings);
    293.  
    294. // /////boots//////
    295.  
    296. // define basic enchantment strings and levels to set
    297. String bootsStr;
    298.  
    299. // get the boots String
    300. String bootsString = getItem(args[0], ".Boots");
    301.  
    302. String[] bootsPartsString = splitString(bootsString, "#");
    303. // ^ split the string into ^
    304. // 1)boots
    305. // 2)enchantment
    306. // 3)level
    307.  
    308. // define the boots string from the split string
    309. bootsStr = bootsPartsString[0];
    310.  
    311. // define the itemstack for the boots
    312. ItemStack boots = new ItemStack(Material.matchMaterial(bootsStr));
    313.  
    314. if (hasEnchantments(bootsString)) { // tests to see if the boots should have enchantments
    315. // fill the enchantmentsArray
    316. fillEnchantments(splitString(bootsPartsString[1], "@"));
    317.  
    318. // fill the enchantmentLevelsArray
    319. fillEnchantmentLevels(splitString(bootsPartsString[2], "@"));
    320.  
    321. // enchant the boots
    322. enchant(boots);
    323.  
    324. } // end the test for multiple enchantments
    325.  
    326. pi.setBoots(boots);
    327.  
    328.  
    329. ////////Additional////////////
    330.  
    331.  
    332.  
    333.  
    334.  
    335. //define basic enchantment strings and levels to set
    336. String additionalStr;
    337. int additionalAmnt;
    338.  
    339. //get the boots String
    340. String additionalString = getItem(args[0], ".Additional.Item");
    341. String additionalAmount = getItem(args[0], ".Additional.Amount");
    342.  
    343. //split the boots String
    344. String[] additionalParts = splitString(additionalString, ",");
    345. String[] additionalPartsAmount = splitString(additionalAmount, ",");
    346.  
    347. for(String s : additionalParts) { //cycles through each boots
    348. String[] additionalPartsString = splitString(s, "#");
    349. //^ split the string into ^
    350. //1)boots
    351. //2)enchantment
    352. //3)level
    353.  
    354. //define the boots string from the split string
    355. additionalStr = additionalPartsString[0];
    356. additionalAmnt = Integer.parseInt(additionalPartsAmount[fillAdditional(additionalParts).indexOf(s)]);
    357.  
    358. //define the itemstack for the boots
    359. ItemStack additional = new ItemStack(Material.matchMaterial(additionalStr), additionalAmnt);
    360.  
    361. if(hasEnchantments(s)) { //tests to see if the boots should have enchantments
    362. //fill the enchantmentsArray
    363. fillEnchantments(splitString(additionalPartsString[1], "@"));
    364.  
    365. //fill the enchantmentLevelsArray
    366. fillEnchantmentLevels(splitString(additionalPartsString[2], "@"));
    367.  
    368. //enchant the boots
    369. enchant(additional);
    370.  
    371. } //end the test for multiple enchantments
    372.  
    373. pi.addItem(additional);
    374. }
    375.  
    376. p.sendMessage(ChatColor.GREEN + "You got your kit!");
    377. return true;
    378. } catch(Exception e){
    379. getServer().getConsoleSender().sendMessage(ChatColor.RED +"The kits.yml is incorrectly configured!");
    380. e.printStackTrace();
    381. return true;
    382. }
    383. } //ends the command for /kit [name]
    384. } //ends the command for /kit
    385. return false;
    386. } //ends the command test for all commands
    387.  
    388. ArrayList<String> fillAdditional(String[] parts) {
    389. ArrayList<String> list = new ArrayList<String>();
    390. for(String s : parts) {
    391. list.add(s);
    392. }
    393. return list;
    394. }
    395.  
    396. ItemStack enchant(ItemStack item) {
    397. for(String ench : enchantments) {
    398. //define the enchantment level by getting the index of the corresponding enchantment then parse that string to an int
    399. int enchantmentLevelStr = Integer.parseInt(enchantmentLevels.get(enchantments.indexOf(ench)));
    400.  
    401. //create the weapon from the string with the given enchantment
    402. item.addUnsafeEnchantment(Enchantment.getByName(ench), enchantmentLevelStr);
    403. } //all enchantments should be added to the weapon now
    404. return item;
    405. }
    406.  
    407. void fillEnchantmentLevels(String[] splitEnchantmentLevels) {
    408. //clear the list before adding to it so you don't give other weapon's enchantment
    409. enchantmentLevels.clear();
    410.  
    411. //cycles through adding all the enchantments after splitting the string
    412. for(String enchantment : splitEnchantmentLevels) {
    413. enchantmentLevels.add(enchantment);
    414. }
    415. return;
    416. }
    417.  
    418. public void fillEnchantments(String[] splitEnchantments) {
    419. //clear the list before adding to it so you don't give other weapon's enchantment
    420. enchantments.clear();
    421.  
    422. //cycles through adding all the enchantments after splitting the string
    423. for(String enchantment : splitEnchantments) {
    424. enchantments.add(enchantment);
    425. }
    426. return;
    427. }
    428.  
    429. //splits the string into parts
    430. public String[] splitString(String toSplit, String regex) {
    431. return toSplit.split(regex); //example toSplit = weapon regex = "," splits it every comma
    432. }
    433.  
    434. //receives the item from the kits.yml
    435. public String getItem(String item, String path) {
    436. return kitFileConfig.getString(item.toUpperCase() + path);
    437. }
    438.  
    439. //checks to see if the item has enchantments
    440. public boolean hasEnchantments(String test) {
    441. String regex = "#";
    442. if(test.contains(regex)) return true;
    443. else return false;
    444. }
    445.  
    446. //checks to see if the item has more than one enchantments
    447. public boolean hasMultipleEnchantments(String test) {
    448. String regex = "@";
    449. if(test.contains(regex)) return true;
    450. else return false;
    451. }
    452.  
    453. //checks to see if the kit exists in kits.yml
    454. public boolean isKit(String kit) {
    455. if(kitFileConfig.contains(kit.toUpperCase())) return true;
    456. if(!kitFileConfig.contains(kit.toUpperCase())) return false;
    457. return false;
    458. }
    459.  
    460. //checks to see if the economy is enabled in the config
    461. public boolean isEconomyEnabled() {
    462. return this.getConfig().getBoolean("Economy.Enabled");
    463. }
    464.  
    465. //loads all the yaml files
    466. public FileConfiguration loadYamls() {
    467. if(!kitFile.exists()) { //make sure the kit exists
    468. try {
    469. kitFile.createNewFile(); //create the file if it doesn't
    470. getLogger().info("Couldn't find the kits.yml file - making a new one!"); //notify user of creation
    471. } catch (IOException e) {
    472. getServer().getConsoleSender().sendMessage(ChatColor.RED +"An error occured while creating the file kits.yml!" + e.getMessage()); //notify user if error occurs
    473. }
    474. }
    475.  
    476. //make sure the kit exists
    477. if(kitFile.exists()) {
    478. try {
    479. //reload the config file in use with the file
    480. kitFileConfig = YamlConfiguration.loadConfiguration(kitFile);
    481.  
    482. } catch (Exception e) {
    483. e.printStackTrace();
    484. }
    485. }
    486. return kitFileConfig;
    487. }
    488.  
    489. //saves all the yaml files
    490. public void saveYamls() {
    491. try {
    492. loadYamls(); //update all yaml files before attempting to save them
    493. kitFileConfig.save(kitFile); //saves the FileConfiguration to its File
    494.  
    495. } catch (IOException e) {
    496. e.printStackTrace();
    497. }
    498. }
    499.  
    500. //basic Vault economy setup method
    501. private boolean setupEconomy() {
    502. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    503. return false;
    504. }
    505. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    506. if (rsp == null) {
    507. return false;
    508. }
    509. econ = rsp.getProvider();
    510. return econ != null;
    511. }
    512.  
    513. }

    Listener Class
    Code:java
    1. package me.connor.kit;
    2.  
    3. import net.milkbowl.vault.economy.Economy;
    4. import net.milkbowl.vault.economy.EconomyResponse;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.block.Sign;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.block.SignChangeEvent;
    14. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    15. import org.bukkit.event.entity.PlayerDeathEvent;
    16. import org.bukkit.event.player.PlayerInteractEvent;
    17. import org.bukkit.inventory.ItemStack;
    18.  
    19. public class KitListener implements Listener {
    20. Main plugin;
    21.  
    22. public KitListener(Main instance) {
    23. plugin = instance;
    24. }
    25.  
    26. @EventHandler
    27. public void onSignChange(SignChangeEvent e) {
    28. if (e.getLine(0).equalsIgnoreCase("[AdvancedKits]")) {
    29. e.setLine(0, plugin.getConfig().getString("Signs.Line1").replaceAll("&", "§"));
    30. e.setLine(1, plugin.getConfig().getString("Signs.Line2").replaceAll("&", "§"));
    31. e.setLine(2, e.getLine(2));
    32. e.setLine(3, plugin.getConfig().getString("Signs.Line4").replaceAll("&", "§"));
    33. }
    34. }
    35.  
    36. @EventHandler
    37. public void onPlayerDeath(PlayerDeathEvent e) {
    38. Player p = e.getEntity();
    39.  
    40. //return if the killer wasn't a player
    41. if(!(p.getKiller() instanceof Player)) return;
    42.  
    43. //define the killer once we know it is a player
    44. Player k = (Player) p.getKiller();
    45.  
    46. //check to see if the economy is enabled
    47. if(plugin.isEconomyEnabled()) {
    48. //get the reward value from the config
    49. double pay = plugin.getConfig().getDouble("Economy.Reward");
    50.  
    51. //deposit the money
    52. EconomyResponse r = plugin.econ.depositPlayer(k.getName(), pay);
    53.  
    54. //if success then message
    55. if(r.transactionSuccess()) {
    56. p.sendMessage(ChatColor.GREEN + "You got $" + pay + " for killing " + p.getName());
    57. }
    58. }
    59. }
    60.  
    61. @EventHandler
    62. public void onPlayerInteract(PlayerInteractEvent e) {
    63. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    64. if (e.getClickedBlock().getState() instanceof Sign) {
    65. Sign sign = (Sign) e.getClickedBlock().getState();
    66. if(plugin.kitFileConfig.contains(sign.getLine(2).toUpperCase())) {
    67. try {
    68. if(plugin.isEconomyEnabled()) {
    69. //get the cost of the kit from the config
    70. double cost = plugin.kitFileConfig.getDouble(sign.getLine(2).toUpperCase() + ".Price");
    71.  
    72. //withdraw the money
    73. EconomyResponse r = plugin.econ.withdrawPlayer(e.getPlayer().getName(), cost);
    74. }
    75.  
    76. //clear the player's inventory before giving them items
    77. e.getPlayer().getInventory().clear();
    78.  
    79. //define basic enchantment strings and levels to set
    80. String weaponStr;
    81.  
    82. //get the weapon String
    83. String weaponString = plugin.getItem(sign.getLine(2), ".Weapon");
    84.  
    85. //split the weapon String
    86. String[] weaponParts = plugin.splitString(weaponString, ",");
    87.  
    88. for(String s : weaponParts) {//cycles through each weapon
    89. String[] weaponPartsString = plugin.splitString(s, "#");
    90. //^ split the string into ^
    91. //1)weapon
    92. //2)enchantment
    93. //3)level
    94.  
    95. //define the weapon string from the parts
    96. weaponStr = weaponPartsString[0];
    97.  
    98. //define the itemstack for the weapon
    99. ItemStack weapon = new ItemStack(Material.matchMaterial(weaponStr));
    100.  
    101. if(plugin.hasEnchantments(s)) {//tests to see if the weapon should have enchantments
    102. //fill the enchantmentsArray
    103. plugin.fillEnchantments(plugin.splitString(weaponPartsString[1], "@"));
    104. //fill the enchantmentLevelsArray
    105. plugin.fillEnchantmentLevels(plugin.splitString(weaponPartsString[2], "@"));
    106. //enchant the weapon
    107. weapon = plugin.enchant(weapon);
    108. }//end the test for multiple enchantments
    109.  
    110. e.getPlayer().getInventory().addItem(weapon);
    111. }//end the cycling of all weapons
    112.  
    113.  
    114.  
    115.  
    116.  
    117.  
    118. //////////////helmet////////////////
    119.  
    120.  
    121.  
    122.  
    123.  
    124.  
    125.  
    126. // define basic enchantment strings and levels to set
    127. String helmetStr;
    128.  
    129. // get the helmet String
    130. String helmetString = plugin.getItem(sign.getLine(2).toUpperCase(), ".Helmet");
    131.  
    132. String[] helmetPartsString = plugin.splitString(helmetString, "#");
    133. // ^ split the string into ^
    134. // 1)weapon
    135. // 2)enchantment
    136. // 3)level
    137.  
    138. // define the weapon string from the split string
    139. helmetStr = helmetPartsString[0];
    140.  
    141. // define the itemstack for the weapon
    142. ItemStack helmet = new ItemStack(Material.matchMaterial(helmetStr));
    143.  
    144. if (plugin.hasEnchantments(helmetString)) { // tests to see if the helmet should have enchantments
    145. // fill the enchantmentsArray
    146. plugin.fillEnchantments(plugin.splitString(helmetPartsString[1], "@"));
    147.  
    148. // fill the enchantmentLevelsArray
    149. plugin.fillEnchantmentLevels(plugin.splitString(helmetPartsString[2], "@"));
    150.  
    151. // enchant the helmet
    152. plugin.enchant(helmet);
    153.  
    154. } // end the test for multiple enchantments
    155.  
    156. e.getPlayer().getInventory().setHelmet(helmet);
    157.  
    158.  
    159.  
    160. //////////////chestplate////////////////
    161.  
    162.  
    163.  
    164.  
    165.  
    166. // define basic enchantment strings and levels to set
    167. String chestplateStr;
    168.  
    169. // get the helmet String
    170. String chesplateString = plugin.getItem(sign.getLine(2), ".Chestplate");
    171.  
    172. String[] chestplatePartsString = plugin.splitString(chesplateString, "#");
    173. // ^ split the string into ^
    174. // 1)weapon
    175. // 2)enchantment
    176. // 3)level
    177.  
    178. // define the weapon string from the split string
    179. chestplateStr = chestplatePartsString[0];
    180.  
    181. // define the itemstack for the chestplate
    182. ItemStack chestplate = new ItemStack(Material.matchMaterial(chestplateStr));
    183.  
    184. if (plugin.hasEnchantments(chesplateString)) { // tests to see if the chestplate should have enchantments
    185. // fill the enchantmentsArray
    186. plugin.fillEnchantments(plugin.splitString(chestplatePartsString[1],
    187. "@"));
    188.  
    189. // fill the enchantmentLevelsArray
    190. plugin.fillEnchantmentLevels(plugin.splitString(chestplatePartsString[2], "@"));
    191.  
    192. // enchant the helmet
    193. plugin.enchant(chestplate);
    194.  
    195. } // end the test for multiple enchantments
    196.  
    197. e.getPlayer().getInventory().setChestplate(chestplate);
    198.  
    199. // ////////////leggings////////////////
    200.  
    201. // define basic enchantment strings and levels to set
    202. String leggingsStr;
    203.  
    204. // get the leggings String
    205. String leggingsString = plugin.getItem(sign.getLine(2).toUpperCase(), ".Leggings");
    206.  
    207. String[] leggingsPartsString = plugin.splitString(leggingsString, "#");
    208. // ^ split the string into ^
    209. // 1)weapon
    210. // 2)enchantment
    211. // 3)level
    212.  
    213. // define the leggings string from the split string
    214. leggingsStr = leggingsPartsString[0];
    215.  
    216. // define the itemstack for the chestplate
    217. ItemStack leggings = new ItemStack(
    218. Material.matchMaterial(leggingsStr));
    219.  
    220. if (plugin.hasEnchantments(leggingsString)) { // tests to see if the leggings should have enchantments
    221. // fill the enchantmentsArray
    222. plugin.fillEnchantments(plugin.splitString(leggingsPartsString[1], "@"));
    223.  
    224. // fill the enchantmentLevelsArray
    225. plugin.fillEnchantmentLevels(plugin.splitString(leggingsPartsString[2], "@"));
    226.  
    227. // enchant the leggings
    228. plugin.enchant(leggings);
    229.  
    230. } // end the test for multiple enchantments
    231.  
    232. e.getPlayer().getInventory().setLeggings(leggings);
    233.  
    234. // /////boots//////
    235.  
    236. // define basic enchantment strings and levels to set
    237. String bootsStr;
    238.  
    239. // get the boots String
    240. String bootsString = plugin.getItem(sign.getLine(2).toUpperCase(), ".Boots");
    241.  
    242. String[] bootsPartsString = plugin.splitString(bootsString, "#");
    243. // ^ split the string into ^
    244. // 1)boots
    245. // 2)enchantment
    246. // 3)level
    247.  
    248. // define the boots string from the split string
    249. bootsStr = bootsPartsString[0];
    250.  
    251. // define the itemstack for the boots
    252. ItemStack boots = new ItemStack(Material.matchMaterial(bootsStr));
    253.  
    254. if (plugin.hasEnchantments(bootsString)) { // tests to see if the boots should have enchantments
    255. // fill the enchantmentsArray
    256. plugin.fillEnchantments(plugin.splitString(bootsPartsString[1], "@"));
    257.  
    258. // fill the enchantmentLevelsArray
    259. plugin.fillEnchantmentLevels(plugin.splitString(bootsPartsString[2], "@"));
    260.  
    261. // enchant the boots
    262. plugin.enchant(boots);
    263.  
    264. } // end the test for multiple enchantments
    265.  
    266. e.getPlayer().getInventory().setBoots(boots);
    267.  
    268.  
    269. ////////Additional////////////
    270.  
    271.  
    272.  
    273.  
    274.  
    275. //define basic enchantment strings and levels to set
    276. String additionalStr;
    277. int additionalAmnt;
    278.  
    279. //get the boots String
    280. String additionalString = plugin.getItem(sign.getLine(2).toUpperCase(), ".Additional.Item");
    281. String additionalAmount = plugin.getItem(sign.getLine(2).toUpperCase(), ".Additional.Amount");
    282.  
    283. //split the boots String
    284. String[] additionalParts = plugin.splitString(additionalString, ",");
    285. String[] additionalPartsAmount = plugin.splitString(additionalAmount, ",");
    286.  
    287. for(String s : additionalParts) {//cycles through each boots
    288. String[] additionalPartsString = plugin.splitString(s, "#");
    289. //^ split the string into ^
    290. //1)boots
    291. //2)enchantment
    292. //3)level
    293.  
    294. //define the boots string from the split string
    295. additionalStr = additionalPartsString[0];
    296. additionalAmnt = Integer.parseInt(additionalPartsAmount[plugin.fillAdditional(additionalParts).indexOf(s)]);
    297.  
    298. //define the itemstack for the boots
    299. ItemStack additional = new ItemStack(Material.matchMaterial(additionalStr), additionalAmnt);
    300.  
    301. if(plugin.hasEnchantments(s)) {//tests to see if the boots should have enchantments
    302. //fill the enchantmentsArray
    303. plugin.fillEnchantments(plugin.splitString(additionalPartsString[1], "@"));
    304.  
    305. //fill the enchantmentLevelsArray
    306. plugin.fillEnchantmentLevels(plugin.splitString(additionalPartsString[2], "@"));
    307.  
    308. //enchant the boots
    309. plugin.enchant(additional);
    310.  
    311. }//end the test for multiple enchantments
    312.  
    313. e.getPlayer().getInventory().addItem(additional);
    314. }
    315.  
    316. e.getPlayer().openInventory(e.getPlayer().getInventory());
    317. e.getPlayer().closeInventory();
    318. e.getPlayer().sendMessage(ChatColor.GREEN + "You got your kit!");
    319. return;
    320. }
    321. catch(Exception ex){
    322. plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED +"The kits.yml is incorrectly configured!");
    323. return;
    324. }
    325. }
    326. }
    327. }
    328. }
    329.  
     
  2. Offline

    Barnyard_Owl

    You'll need to call player.updateInventory() after changing the inventory.
     
    cfil360 likes this.
  3. Offline

    cfil360

Thread Status:
Not open for further replies.

Share This Page