Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. public class CosmeticTask extends BukkitRunnable {
  2.  
  3.     private ItemStack getColorArmor(Material m, Color c) {
  4.         ItemStack i = new ItemStack(m, 1); {
  5.             LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
  6.  
  7.             meta.setColor(c);
  8.  
  9.             i.setItemMeta(meta);
  10.         }
  11.  
  12.         return i;
  13.     }
  14.  
  15.     private String stripDisplayName(ItemStack i) {
  16.         return ChatColor.stripColor(i.getItemMeta().getDisplayName());
  17.     }
  18.  
  19.     @Override
  20.     public void run() {
  21.         Random r = ThreadLocalRandom.current();
  22.         Color c = Color.fromRGB(r.nextInt(255), r.nextInt(255), r.nextInt(255));
  23.  
  24.         for (Player p : Bukkit.getServer().getOnlinePlayers()) {
  25.             ItemStack helmet = p.getInventory().getHelmet();
  26.             ItemStack chestplate = p.getInventory().getChestplate();
  27.             ItemStack leggings = p.getInventory().getLeggings();
  28.             ItemStack boots = p.getInventory().getBoots();
  29.  
  30.             if (helmet != null && helmet.getType().equals(Material.LEATHER_HELMET)) {
  31.                 p.getInventory().setHelmet(getColorArmor(Material.LEATHER_HELMET, c));
  32.             }
  33.  
  34.             if (chestplate != null && chestplate.getType().equals(Material.LEATHER_CHESTPLATE)) {
  35.                 p.getInventory().setChestplate(getColorArmor(Material.LEATHER_CHESTPLATE, c));
  36.             }
  37.  
  38.             if (leggings != null && leggings.getType().equals(Material.LEATHER_LEGGINGS)) {
  39.                 p.getInventory().setLeggings(getColorArmor(Material.LEATHER_LEGGINGS, c));
  40.             }
  41.  
  42.             if (boots != null && boots.getType().equals(Material.LEATHER_BOOTS)) {
  43.                 p.getInventory().setBoots(getColorArmor(Material.LEATHER_BOOTS, c));
  44.             }
  45.  
  46. //            if (p.getInventory().getHelmet() != null && p.getInventory().getHelmet().getType() == Material.LEATHER_HELMET && ChatColor.stripColor(p.getInventory().getHelmet().getItemMeta().getDisplayName()).equalsIgnoreCase("Reward Helmet")) {
  47. //                p.getInventory().setHelmet(getColorArmor(Material.LEATHER_HELMET, c));
  48. //            }
  49. //
  50. //            if (p.getInventory().getChestplate() != null && p.getInventory().getChestplate().getType() == Material.LEATHER_CHESTPLATE && ChatColor.stripColor(p.getInventory().getChestplate().getItemMeta().getDisplayName()).equalsIgnoreCase("Reward Chestplate")) {
  51. //                p.getInventory().setChestplate(getColorArmor(Material.LEATHER_CHESTPLATE, c));
  52. //            }
  53. //
  54. //            if (p.getInventory().getLeggings() != null && p.getInventory().getLeggings().getType() == Material.LEATHER_LEGGINGS && ChatColor.stripColor(p.getInventory().getLeggings().getItemMeta().getDisplayName()).equalsIgnoreCase("Reward Leggings")) {
  55. //                p.getInventory().setLeggings(getColorArmor(Material.LEATHER_LEGGINGS, c));
  56. //            }
  57. //
  58. //            if (p.getInventory().getBoots() != null && p.getInventory().getBoots().getType() == Material.LEATHER_BOOTS && ChatColor.stripColor(p.getInventory().getBoots().getItemMeta().getDisplayName()).equalsIgnoreCase("Reward Boots")) {
  59. //                p.getInventory().setBoots(getColorArmor(Material.LEATHER_BOOTS, c));
  60. //            }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement