Solved Coloured Leather Armour

Discussion in 'Plugin Development' started by FlareLine, Apr 6, 2014.

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

    FlareLine

    Hi all,
    I currently have a plugin that puts players into a team when they execute a command e.g. /ms join red and then when /ms start is used, they are given dyed leather armour of the colour of their team.
    However it does not seem to be working at the moment, the armour that is given is not dyed.
    Would someone be ale to help me with this?
    Show Spoiler

    Code:java
    1. package me.genki.ms;
    2.  
    3. import java.util.Set;
    4.  
    5. import me.genki.ms.team.Armour;
    6. import me.genki.ms.team.GameHandler;
    7.  
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. @SuppressWarnings("unused")
    15. public class MineSide extends JavaPlugin {
    16.  
    17. private MineSide ms;
    18. private GameHandler gh = new GameHandler();
    19. private Armour am = new Armour();
    20.  
    21. public void onEnable() {
    22. }
    23.  
    24. public void onDisable() {
    25.  
    26. }
    27.  
    28. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    29. if(cmd.getName().equalsIgnoreCase("ms")) {
    30. if(sender instanceof Player){
    31. if(args.length > 1){
    32. if(args[0].equalsIgnoreCase("join")) {
    33. String team = args[1];
    34. int i = cTeam(team);
    35. Integer ii = (Integer) i;
    36. if(ii == 9){
    37. return true;
    38. } else {
    39. gh.setTeam((Player) sender, i);
    40. return true;
    41. }
    42. }
    43. return true;
    44. }
    45. if(args.length == 0){
    46. sender.sendMessage(ChatColor.GOLD + "-------------------------------------");
    47. sender.sendMessage(ChatColor.BLUE + "MineSide" + ChatColor.AQUA + "2");
    48. sender.sendMessage(ChatColor.GOLD + "-------------------------------------");
    49. sender.sendMessage(ChatColor.GREEN + "By FlareLine and the AuzRealmz Team");
    50. sender.sendMessage(ChatColor.GOLD + "-------------------------------------");
    51. return true;
    52. }
    53. if(args.length == 1){
    54. if(args[0].equalsIgnoreCase("start")){
    55. try {
    56. Player p = (Player) sender;
    57. Integer i = gh.pteams.get(p);
    58. am.clothing(p, i);
    59. } catch (Exception e){
    60. e.printStackTrace();
    61. }
    62. }
    63. }
    64. return true;
    65. }
    66. return true;
    67. }
    68. return false;
    69. }
    70.  
    71. public Integer cTeam(String team) {
    72. int i = 9;
    73. String t = team.toLowerCase();
    74. if ((t.equalsIgnoreCase("red")) || (t.equalsIgnoreCase("r"))) {
    75. i = 2;
    76. return i;
    77. }
    78. if ((t.equalsIgnoreCase("green")) || (t.equalsIgnoreCase("g"))) {
    79. i = 1;
    80. return i;
    81. }
    82. if ((t.equalsIgnoreCase("blue")) || (t.equalsIgnoreCase("b"))) {
    83. i = 3;
    84. return i;
    85. }
    86. return i;
    87. }
    88. }
    89.  


    Show Spoiler

    Code:java
    1. package me.genki.ms.team;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.LinkedHashMap;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.entity.Player;
    8.  
    9. public class GameHandler {
    10.  
    11. public ArrayList<Player[]> players = new ArrayList<Player[]>();
    12. public LinkedHashMap<Player, Integer> pteams = new LinkedHashMap<Player, Integer>();
    13.  
    14. /**
    15.   * @param p
    16.   * Player
    17.   * @param t
    18.   * Team
    19.   */
    20. public void setTeam(Player p, Integer t) {
    21. switch (t) {
    22.  
    23. case (0):
    24. pteams.remove(p);
    25. p.sendMessage(ChatColor.AQUA + "You are now not in a team!");
    26. break;
    27. case (1):
    28. pteams.put(p, t);
    29. p.sendMessage(ChatColor.GREEN + "You are now on the GREEN team!");
    30. break;
    31. case (2):
    32. pteams.put(p, t);
    33. p.sendMessage(ChatColor.RED + "You are now on the RED team!");
    34. break;
    35. case (3):
    36. pteams.put(p, t);
    37. p.sendMessage(ChatColor.BLUE + "You are now on the BLUE team!");
    38. break;
    39. default:
    40. p.sendMessage("Wrong team");
    41. break;
    42. }
    43. }
    44. }
    45.  


    Show Spoiler

    Code:java
    1. package me.genki.ms.team;
    2.  
    3. import org.bukkit.Color;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.inventory.ItemStack;
    7. import org.bukkit.inventory.meta.LeatherArmorMeta;
    8.  
    9. public class Armour {
    10.  
    11. public ItemStack helm = new ItemStack(Material.LEATHER_HELMET);
    12. public ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE);
    13. public ItemStack legs = new ItemStack(Material.LEATHER_LEGGINGS);
    14. public ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
    15.  
    16. public final Color redc = Color.fromRGB(255, 0, 0);
    17. public final Color greenc = Color.fromRGB(0, 255, 0);
    18. public final Color bluec = Color.fromRGB(0, 0, 255);
    19.  
    20. /**
    21.   * Give the Player the specified team's armour
    22.   *
    23.   * @param p
    24.   * Player to provide for
    25.   *
    26.   * @param i
    27.   * Team ID GREEN: 1 RED: 2 BLUE: 3
    28.   */
    29. public void clothing(Player p, Integer i) {
    30.  
    31. final LeatherArmorMeta lamh = (LeatherArmorMeta) helm.getItemMeta();
    32. final LeatherArmorMeta lamc = (LeatherArmorMeta) chest.getItemMeta();
    33. final LeatherArmorMeta laml = (LeatherArmorMeta) legs.getItemMeta();
    34. final LeatherArmorMeta lamb = (LeatherArmorMeta) boots.getItemMeta();
    35. try {
    36. switch (i) {
    37. case (1):
    38. lamh.setColor(greenc);
    39. lamc.setColor(greenc);
    40. laml.setColor(greenc);
    41. lamb.setColor(greenc);
    42. p.getInventory().addItem(helm);
    43. p.getInventory().addItem(chest);
    44. p.getInventory().addItem(legs);
    45. p.getInventory().addItem(boots);
    46. break;
    47. case (2):
    48. lamh.setColor(redc);
    49. lamc.setColor(redc);
    50. laml.setColor(redc);
    51. lamb.setColor(redc);
    52. p.getInventory().addItem(helm);
    53. p.getInventory().addItem(chest);
    54. p.getInventory().addItem(legs);
    55. p.getInventory().addItem(boots);
    56. break;
    57. case (3):
    58. lamh.setColor(bluec);
    59. lamc.setColor(bluec);
    60. laml.setColor(bluec);
    61. lamb.setColor(bluec);
    62. p.getInventory().addItem(helm);
    63. p.getInventory().addItem(chest);
    64. p.getInventory().addItem(legs);
    65. p.getInventory().addItem(boots);
    66. break;
    67. default:
    68. break;
    69. }
    70. } catch (Exception e) {
    71. e.printStackTrace();
    72. }
    73. }
    74. }
    75.  



    Sorry for the formatting of the code, I clean it up last! :)
    Cheers.
     
  2. Offline

    Gater12

  3. Offline

    FlareLine

    Gater12 ItemMeta does not have a method for setting Leather Armour colour, therefore I needed to cast to LeatherArmorMeta as per the Armour class.
     
  4. Offline

    BillyGalbreath

    You are setting the color to the meta, but not setting the meta to the item.
     
  5. Offline

    Mr360zack

    You need to set the itemMeta to the armor.
    Also you can just do Color.GREEN and stuff.
     
  6. Offline

    FlareLine

    BillyGalbreath Oops, Didn't realise you had to do that: never done any of this sort of stuff before.
    Thanks!
    Mr360zack I plan to do a slightly different colour, that's why I'm going for the RGB
     
  7. Offline

    Gater12

  8. Offline

    AoH_Ruthless

    FlareLine
    You could also look into LeatherArmorMeta and set its color to Color.RED;

    Edit: Crap, should probably read the other posts next time
     
  9. Offline

    FlareLine

Thread Status:
Not open for further replies.

Share This Page