Changing Armor Color more smoothly

Discussion in 'Spigot Plugin Development' started by ryu, Jun 29, 2016.

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

    ryu

    Hello, I am trying to create a plugin that allows the user to put on armor that would change colors. But I already know how to setup the armor with the colors to change my only issue is to be able to make the colors run more smoothly like so:

    [​IMG]

    Would anyone possibly know how this would be done???

    Note: Ignore the particles.

    My Code:
    Code (Text):
    import java.util.Random;

    import org.bukkit.Bukkit;
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    public class DiscoArmor extends JavaPlugin {

        public void onEnable() {
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                private Random r = new Random();
           
                public void run() {
                    Color c = Color.fromRGB(r.nextInt(255), r.nextInt(255), r.nextInt(255));
               
                    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                        if (p.getInventory().getHelmet() != null && p.getInventory().getHelmet().getType() == Material.LEATHER_HELMET && p.getInventory().getHelmet().getItemMeta().getDisplayName().equals("§4§lR§6§la§e§li§a§ln§b§lb§1§lo§5§lw §d§lA§4§lr§6§lm§e§lo§a§lr")) {
                            p.getInventory().setHelmet(getColorArmor(Material.LEATHER_HELMET, c));
                        }
                   
                        if (p.getInventory().getChestplate() != null && p.getInventory().getChestplate().getType() == Material.LEATHER_CHESTPLATE && p.getInventory().getChestplate().getItemMeta().getDisplayName().equals("§4§lR§6§la§e§li§a§ln§b§lb§1§lo§5§lw §d§lA§4§lr§6§lm§e§lo§a§lr")) {
                            p.getInventory().setChestplate(getColorArmor(Material.LEATHER_CHESTPLATE, c));
                        }
                   
                        if (p.getInventory().getLeggings() != null && p.getInventory().getLeggings().getType() == Material.LEATHER_LEGGINGS && p.getInventory().getLeggings().getItemMeta().getDisplayName().equals("§4§lR§6§la§e§li§a§ln§b§lb§1§lo§5§lw §d§lA§4§lr§6§lm§e§lo§a§lr")) {
                            p.getInventory().setLeggings(getColorArmor(Material.LEATHER_LEGGINGS, c));
                        }
                   
                        if (p.getInventory().getBoots() != null && p.getInventory().getBoots().getType() == Material.LEATHER_BOOTS && p.getInventory().getBoots().getItemMeta().getDisplayName().equals("§4§lR§6§la§e§li§a§ln§b§lb§1§lo§5§lw §d§lA§4§lr§6§lm§e§lo§a§lr")) {
                            p.getInventory().setBoots(getColorArmor(Material.LEATHER_BOOTS, c));
                        }
                    }
                }
            }, 0, 50);
        }

        private ItemStack getColorArmor(Material m, Color c) {
            ItemStack i = new ItemStack(m, 1);
            LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
            meta.setColor(c);
            meta.setDisplayName("§4§lR§6§la§e§li§a§ln§b§lb§1§lo§5§lw §d§lA§4§lr§6§lm§e§lo§a§lr");
            meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 10, true);
            meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
            i.setItemMeta(meta);
            return i;
        }
    }
     
    #1 ryu, Jun 29, 2016
    Last edited: Jun 29, 2016
  2. First off. Dont hardcode your color codes. Its bad practice. Second, you can increase the Color that the armor already has and if it reaches its max then start decreasing.
     
  3. ryu

    ryu

    How exactly would I do that may I ask? (The second part of course)
     
  4. You should watch this video, may help
     
  5. LeatherArmorMeta
    setColor
     
  6. ryu

    ryu

    Already have watched that.
     
  7. ryu

    ryu

    Updated with better description on what I'm trying to do.
     
  8. Go on google and search for something like rainbow color..

    All you have to do is transition between the colors of a rainbow at a certain pace..
     
Thread Status:
Not open for further replies.