[Util] The Colorizer 2.0 - Custom Events, Useful Methods, and Color Changing Like Never Before!

Discussion in 'Resources' started by BungeeTheCookie, Dec 5, 2013.

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

    BungeeTheCookie

    The Colorizer 2
    Introduction: Hey guys it is BungeeTheCookie here yet again with another library in the resource section! I was thinking about creating a simple way for dying Leather Armour quickly and efficiently! Today, I bring to you guys the Colorizer. The Colorizer utility now makes the dying of Leather Armour simple and fun!​
    UPDATE: This thread has been inactive for quite a while, so I have decided to revive it by introducing The Colorizer 2.0! While the setColor() method is the same, I have rewrote the armorRandomColorChange() method and made preparations for tons of new methods! The biggest change is, there is a new event.​
    Features:
    • Set the color of Leather Armor with ease!
    • Quick and efficient!
    • Use RGB to set the integer of the red, blue, and green arguments to make custom colors!
    • Randomly change the color of the Leather Armour you are wearing with an array of color arguments!
    • A new event, ArmorColorChangeEvent, to trigger events when one of the methods is called.
    Usage:
    SetColor - The setColor() method was the first and is the simplest way to set the color of LeatherArmor. This method requires an ItemStack argument and a Color argument. For even more customization, you can use three integers; Red, Green, and Blue (RGB) to make your own custom colours that are not supported in the Color enumerator!

    Example:
    PHP:
    //Default Way
    ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
    Colorizer.setColor(helmetColor.YELLOW)
     
    //Or use the RGB!
    ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
    Colorizer.setColor(chestplate696969);
     

    ArmorRandomColorChange - The armorRandomColorChange() method requires a JavaPlugin, which is your main class, a Player, two doubles (a repeat delay and time) and an array of colors. This method instantiates a BukkitRunnable, which requires a JavaPlugin. The Player argument will check and see if a player is wearing leather armour, and if it does, it will change the color. Since this method instantiates a BukkitRunnable and uses a tasktimer, it requires a repeat delay. The repeat delay is the time the runnable is delayed before it repeats again. The long argument for this is in ticks, which is 1-20th of a second. Then there is the time, which is the time the BukkitRunnable will keep repeating until it is cancelled. This is done in seconds (20 ticks). Then there is a boolean that allows for a stack trace to be printed if something goes wrong. Finally, our last argument is an array of colors. This method gets the colors you have in your argument, randomizes it, and then changes the colour of your armour randomly. You can have from three arguments to fifteen color arguments! No matter how many color arguments you have, it will put it into a list, randomize it, and dye the LeatherArmour the player is wearing!

    Example:
    PHP:
    //Random Armour Color Change Using Custom Colour Arguments!
    Colorizer.armorRandomColorChange(thise.getPlayer(), 2069trueColor.BLUEColor.REDColor.YELLOW)

    ArmorColorChangeEvent

    New in version 2.0, is the ArmorColorChangeEvent! No, it is not a method, it is a separate class that extends Event, so it functions as a regular Bukkit event! You need your @EventHandler annotation and have your class implement Listener in order for this to have any value. In this class, you can use getItem() to return the ItemStack, getItemMeta() to return the ItemMeta, getColor() to get the color of the armour, setColor() to set the color of the armour, and getWearer() to return the player who is wearing the armour!


    Closing: In closing, I wanted to say that anyone could contribute code, methods, or fields to this library, and I will update it whenever I can. If there are any errors, you can tag me using @BungeeTheCookie. To end this awesome resource, I will post the Colorizer code.

    Colorizer Class:
    PHP:
    package bungeecookie.mineworks.api.util;
     
    import bungeecookie.mineworks.api.event.ArmorColorChangeEvent;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
     
    import java.util.Arrays;
    import java.util.List;
    import java.util.Random;
     
    public class 
    Colorizer {
     
        public static 
    ItemStack setColor(ItemStack itemint rint gint b){
            
    LeatherArmorMeta lam = (LeatherArmorMeta)item.getItemMeta();
            
    lam.setColor(Color.fromRGB(rgb));
            
    item.setItemMeta(lam);
            
    Bukkit.getServer().getPluginManager().callEvent(new ArmorColorChangeEvent(itemlam));
            return 
    item;
        }
     
        public static 
    ItemStack setColor(ItemStack itemColor color){
            
    LeatherArmorMeta lam = (LeatherArmorMeta)item.getItemMeta();
            
    lam.setColor(color);
            
    item.setItemMeta(lam);
            
    Bukkit.getServer().getPluginManager().callEvent(new ArmorColorChangeEvent(itemlam));
            return 
    item;
        }
        public static 
    void armorRandomColorChange(final JavaPlugin plugin, final Player player, final long repeatdelay, final long time, final boolean printStackTrace, final Color... color){
            new 
    BukkitRunnable(){
                public 
    void run(){
                    try{
                        for(
    ItemStack i player.getInventory().getArmorContents()){
                            if(
    == new ItemStack(Material.LEATHER_BOOTS) || == new ItemStack(Material.LEATHER_CHESTPLATE) || == new ItemStack(Material.LEATHER_HELMET) || == new ItemStack(Material.LEATHER_LEGGINGS)){
                                
    Color[] colors color;
                                
    Random r = new Random();
                                List<
    ColorcolorList Arrays.asList(colors);
                                
    Color randomColor colorList.get(r.nextInt(colorList.size()));
                                
    setColor(irandomColor);
                            }else{
                                
    Bukkit.getServer().getLogger().warning("[" plugin.getName() + "] [Colorizer] The player " player.getName() + " is not wearing any leather armour!");
                                
    this.cancel();
                                return;
                            }
                        }
                        final 
    int taskID this.getTaskId();
                        new 
    BukkitRunnable(){
                            public 
    void run(){
                                
    Bukkit.getServer().getScheduler().cancelTask(taskID);
                            }
                        }.
    runTaskLater(plugin20 time);
                    }catch(
    Exception e){
                        
    this.cancel();
                        if(
    printStackTrace == true){
                            
    e.printStackTrace();
                        }
                    }
                }
            }.
    runTaskTimer(plugin0Lrepeatdelay);
        }
    }
    ArmorColorChangeEvent Class:
    PHP:
    package bungeecookie.mineworks.api.event;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Color;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Cancellable;
    import org.bukkit.event.Event;
    import org.bukkit.event.HandlerList;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
     
    public class 
    ArmorColorChangeEvent extends Event implements Cancellable {
     
    private static 
    HandlerList handlers = new HandlerList();
    private 
    boolean cancelled;
    public 
    ItemStack item;
    public 
    LeatherArmorMeta itemmeta;
    public 
    Color color;
     
        public 
    ArmorColorChangeEvent(ItemStack itemLeatherArmorMeta meta){
            
    this.item item;
            
    this.itemmeta meta;
            
    this.color meta.getColor();
        }
        @
    Override
        
    public HandlerList getHandlers(){
            return 
    handlers;
        }
     
        public static 
    HandlerList getHandlerList(){
            return 
    handlers;
        }
     
        @
    Override
        
    public boolean isCancelled() {
            return 
    cancelled;
        }
     
        @
    Override
        
    public void setCancelled(boolean value){
            
    cancelled value;
        }
     
        public 
    ItemStack getItem(){
            return 
    item;
        }
     
        public 
    LeatherArmorMeta getItemMeta(){
            return 
    itemmeta;
        }
     
        public 
    Color getColor(){
            return 
    color;
        }
     
        public 
    void setColor(Color color){
            
    itemmeta.setColor(color);
        }
     
     
        public 
    Player getWearer(){
            for(
    Player pBukkit.getServer().getOnlinePlayers()){
                if(
    p.getInventory().contains(item) || p.getInventory().getArmorContents().equals(item)){
                    if(
    item.getItemMeta() == itemmeta){
                        return 
    p;
                    }
                }
            }
            return 
    null;
        }
    }
    Reserved.

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

    YayaBananana

    Good job :)
     
  3. Offline

    BungeeTheCookie

    Thanks :)
     
  4. Offline

    Paxination

    Love this, I am using this for rainbow changing leather armor. Let the colors fly! My Mod loves this resource. She leaves her rainbow armor on all the time!
     
  5. Offline

    BungeeTheCookie

    I am happy to hear that. I will add more features soon. Thank you for the positive feedback :D.
     
  6. Offline

    CrazyGuy3000

    BungeeTheCookie

    NOTE: I edited your error message ;)


    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent event){
            final Player player = event.getPlayer();
     
            player.getInventory().setBoots(new ItemStack(Material.LEATHER_BOOTS));
            Colorizer.armorRandomColorChange(this, player, 20, 69, Color.BLUE);
        }
    Runs the error over and over of

    Code:
    [Wardrobe] _Nova2 isn't wearing any armour!?!
    
     
    BungeeTheCookie likes this.
  7. Offline

    BungeeTheCookie

    Updated to Version 2.0!!!!!!
     
    Dupstal likes this.
Thread Status:
Not open for further replies.

Share This Page