use of org.bukkit.Color in project Denizen-For-Bukkit by DenizenScript.
the class dColor method valueOf.
/**
* Gets a Color Object from a string form.
*
* @param string the string
* @return a Color, or null if incorrectly formatted
*/
@Fetchable("co")
public static dColor valueOf(String string, TagContext context) {
string = string.toUpperCase().replace("CO@", "");
if (string.matches("RANDOM")) {
// Get a color using random RGB values
return new dColor(CoreUtilities.getRandom().nextInt(256), CoreUtilities.getRandom().nextInt(256), CoreUtilities.getRandom().nextInt(256));
}
Matcher m = rgbPattern.matcher(string);
if (m.matches()) {
return new dColor(aH.getIntegerFrom(m.group(1)), aH.getIntegerFrom(m.group(2)), aH.getIntegerFrom(m.group(3)));
}
Field colorField = null;
try {
colorField = Color.class.getField(string.toUpperCase());
} catch (SecurityException e1) {
dB.echoError("Security exception getting color field!");
} catch (NoSuchFieldException e1) {
dB.echoError("No such color field!");
}
if (colorField != null) {
return new dColor(colorField);
}
// No match
return null;
}
use of org.bukkit.Color in project Minigames by AddstarMC.
the class PlayerData method partyMode.
public void partyMode(MinigamePlayer player) {
if (onPartyMode()) {
Location loc = player.getPlayer().getLocation();
Firework firework = (Firework) player.getPlayer().getWorld().spawnEntity(loc, EntityType.FIREWORK);
FireworkMeta fwm = firework.getFireworkMeta();
Random chance = new Random();
Type type = Type.BALL_LARGE;
if (chance.nextInt(100) < 50) {
type = Type.BALL;
}
Color col = Color.fromRGB(chance.nextInt(255), chance.nextInt(255), chance.nextInt(255));
FireworkEffect effect = FireworkEffect.builder().with(type).withColor(col).flicker(chance.nextBoolean()).trail(chance.nextBoolean()).build();
fwm.addEffect(effect);
fwm.setPower(1);
firework.setFireworkMeta(fwm);
}
}
use of org.bukkit.Color in project Glowstone by GlowstoneMC.
the class GlowMetaFireworkEffect method toEffect.
static FireworkEffect toEffect(CompoundTag explosion) {
boolean flicker = false;
boolean trail = false;
Type type;
List<Color> colors = new ArrayList<>();
List<Color> fadeColors = new ArrayList<>();
int[] colorInts = explosion.getIntArray("Colors");
for (int color : colorInts) {
colors.add(Color.fromRGB(color));
}
type = Type.values()[explosion.getByte("Type")];
if (explosion.isByte("Flicker"))
flicker = explosion.getBool("Flicker");
if (explosion.isByte("Trail"))
trail = explosion.getBool("Trail");
if (explosion.isIntArray("FadeColors")) {
int[] fadeInts = explosion.getIntArray("FadeColors");
for (int fade : fadeInts) {
fadeColors.add(Color.fromRGB(fade));
}
}
return FireworkEffect.builder().flicker(flicker).trail(trail).with(type).withColor(colors).withFade(fadeColors).build();
}
use of org.bukkit.Color in project Glowstone by GlowstoneMC.
the class GlowMetaFireworkEffect method toExplosion.
static CompoundTag toExplosion(FireworkEffect effect) {
CompoundTag explosion = new CompoundTag();
if (effect.hasFlicker())
explosion.putBool("Flicker", true);
if (effect.hasTrail())
explosion.putBool("Trail", true);
explosion.putByte("Type", effect.getType().ordinal());
List<Color> colors = effect.getColors();
List<Integer> colorInts = colors.stream().map(Color::asRGB).collect(Collectors.toList());
explosion.putIntArray("Colors", Ints.toArray(colorInts));
List<Color> fade = effect.getFadeColors();
if (!fade.isEmpty()) {
List<Integer> fadeInts = fade.stream().map(Color::asRGB).collect(Collectors.toList());
explosion.putIntArray("FadeColors", Ints.toArray(fadeInts));
}
return explosion;
}
use of org.bukkit.Color in project Glowstone by GlowstoneMC.
the class GlowArmorDyeMatcher method getResult.
@Override
public ItemStack getResult(ItemStack[] matrix) {
ItemStack armor = null;
List<Color> colors = new ArrayList<>();
for (ItemStack item : matrix) {
if (item == null)
continue;
if (item.getType() == Material.INK_SACK) {
Color color = ((Dye) item.getData()).getColor().getColor();
colors.add(color);
continue;
}
if (LEATHERS.matches(item.getType())) {
// Can't dye more than one item
if (armor != null)
return null;
armor = item;
continue;
}
// Non-armor item
return null;
}
// No armor
if (armor == null)
return null;
// No colors
if (colors.isEmpty())
return null;
LeatherArmorMeta meta = (LeatherArmorMeta) armor.getItemMeta();
Color base = meta.getColor();
if (meta.getColor() == GlowItemFactory.instance().getDefaultLeatherColor()) {
base = colors.remove(0);
}
Color newColor = base.mixColors(colors.toArray(new Color[colors.size()]));
ItemStack ret = armor.clone();
LeatherArmorMeta retMeta = (LeatherArmorMeta) ret.getItemMeta();
retMeta.setColor(newColor);
ret.setItemMeta(retMeta);
return ret;
}
Aggregations