Checking for dyed armor

Discussion in 'Plugin Development' started by blueshadow1998, Aug 29, 2014.

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

    blueshadow1998

    Hello dear Bukkit Community.

    I got one simple question:
    How do i check a player, if he wears a dyed armor? (example: red boots).

    I would appreciate every single help :)

    LG,
    blueshadow1998
     
  2. Offline

    jojo1541

    Code:java
    1. LeatherArmorMeta lam = (LeatherArmorMeta)YourLeatherArmorPart.getItemMeta();
    2. Color C = lam.getColor();
     
    hintss and ChipDev like this.
  3. Offline

    ChipDev

    Now check if C is red.
     
  4. Offline

    jojo1541

    I found this in the JavaDocs. It should be no problem with this Enum.
    Code:java
    1. if (C.equals(DyeColor.RED.getColor())) {
    2. //Your Code here
    3. }
     
  5. Offline

    blueshadow1998

    jojo1541

    Thanks for the helpful reply!

    Do you know how to set the color of the armor?

    So that if you type in /boots red, you get red boots?

    Code:java
    1. //Not my whole code ofc.
    2.  
    3. if(cmd.getName().equalsIgnoreCase("boots")) {
    4. Player p1 = (Player) cs;
    5. if(p1.getWorld().getName().equalsIgnoreCase("world")) {
    6. if(args.length == 0) {
    7. cs.sendMessage("ยง4Please enter a color!")
    8. return true;
    9. }
    10. if(args.length == 1) {
    11. if(args[0].equalsIgnoreCase("red")){
    12. p1.getInventory();
    13. p1.getInventory().setBoots(null);
    14. p1.getInventory().setBoots(red);
    15. cs.sendMessage(this.prefix + "You now have red boots!!");
    16. return true;
    17. }
    18. }
     
  6. Offline

    jojo1541

    Code:java
    1. LeatherArmorMeta lam = (LeatherArmorMeta) IS.getItemMeta();
    2. lam.setColor(DyeColor.RED.getColor());
     
  7. Offline

    blueshadow1998

    jojo1541

    Thank you very much, i'll test out soon.
     
  8. Offline

    fireblast709

    jojo1541 such spoonfeed, much sad. Also, you shouldn't use raw colour codes and you forgot to set the ItemMeta after you set the colour.
     
    AdamQpzm and hintss like this.
  9. Offline

    jojo1541

    fireblast709
    it's an example for the method, not a whole code to set/get the color.
    As for the raw values: In my edit i use the Color Enumeration from Bukkit-API. But you are right, i will edit out the raw values.
     
  10. Offline

    fireblast709

    jojo1541 Still, you could've just told him to look at ItemMeta instead, since that would certainly teach him more...
     
  11. Offline

    jojo1541

Thread Status:
Not open for further replies.

Share This Page