Created
July 29, 2014 11:32
-
-
Save truelecter/0947e0c3e5626ee64f1d to your computer and use it in GitHub Desktop.
RainbowArmor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.babon.rainbow; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.List; | |
import org.bukkit.Color; | |
import org.bukkit.Material; | |
import org.bukkit.entity.Player; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.ItemMeta; | |
import org.bukkit.inventory.meta.LeatherArmorMeta; | |
public class RainbowTask implements Runnable { | |
private Rainbow pl; | |
public RainbowTask(Rainbow rainbow) { | |
this.pl = rainbow; | |
} | |
private ItemMeta addLore(ItemStack i) { | |
ItemMeta meta = i.getItemMeta(); | |
List<String> lore = meta.getLore(); | |
if (lore == null) { | |
lore = new ArrayList<String>(); | |
} | |
lore.add(Rainbow.LORESTRING); | |
meta.setLore(lore); | |
return meta; | |
} | |
public void run() { | |
Player p; | |
ItemStack helmet; | |
for (Iterator<Player> localIterator = this.pl.RainbowList.iterator(); localIterator.hasNext(); p | |
.getInventory().setHelmet(helmet)) { | |
p = (Player) localIterator.next(); | |
nextRGB(); | |
ItemStack boots = new ItemStack(Material.LEATHER_BOOTS); | |
ItemStack leggins = new ItemStack(Material.LEATHER_LEGGINGS); | |
ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE); | |
helmet = new ItemStack(Material.LEATHER_HELMET); | |
LeatherArmorMeta meta = (LeatherArmorMeta) boots.getItemMeta(); | |
meta.setColor(Color.fromBGR(this.r, this.g, this.b)); | |
boots.setItemMeta(meta); | |
boots.setItemMeta(addLore(boots)); | |
p.getInventory().setBoots(boots); | |
meta = (LeatherArmorMeta) leggins.getItemMeta(); | |
meta.setColor(Color.fromBGR(this.r, this.g, this.b)); | |
leggins.setItemMeta(meta); | |
leggins.setItemMeta(addLore(leggins)); | |
p.getInventory().setLeggings(leggins); | |
meta = (LeatherArmorMeta) chestplate.getItemMeta(); | |
meta.setColor(Color.fromBGR(this.r, this.g, this.b)); | |
chestplate.setItemMeta(meta); | |
chestplate.setItemMeta(addLore(chestplate)); | |
p.getInventory().setChestplate(chestplate); | |
meta = (LeatherArmorMeta) helmet.getItemMeta(); | |
meta.setColor(Color.fromBGR(this.r, this.g, this.b)); | |
helmet.setItemMeta(meta); | |
helmet.setItemMeta(addLore(helmet)); | |
} | |
} | |
private int r = 255; | |
private int g = 0; | |
private int b = 0; | |
private void nextRGB() { | |
if ((this.r == 255) && (this.g < 255) && (this.b == 0)) { | |
this.g += this.pl.jump; | |
} | |
if ((this.g == 255) && (this.r > 0) && (this.b == 0)) { | |
this.r -= this.pl.jump; | |
} | |
if ((this.g == 255) && (this.b < 255) && (this.r == 0)) { | |
this.b += this.pl.jump; | |
} | |
if ((this.b == 255) && (this.g > 0) && (this.r == 0)) { | |
this.g -= this.pl.jump; | |
} | |
if ((this.b == 255) && (this.r < 255) && (this.g == 0)) { | |
this.r += this.pl.jump; | |
} | |
if ((this.r == 255) && (this.b > 0) && (this.g == 0)) { | |
this.b -= this.pl.jump; | |
} | |
if (this.r > 255) { | |
this.r = 255; | |
} | |
if (this.g > 255) { | |
this.g = 255; | |
} | |
if (this.b > 255) { | |
this.b = 255; | |
} | |
if (this.r < 0) { | |
this.r = 0; | |
} | |
if (this.g < 0) { | |
this.g = 0; | |
} | |
if (this.b < 0) { | |
this.b = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment