org.bukkit.DyeColor Java Examples

The following examples show how to use org.bukkit.DyeColor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Wool and Dye. But Dye is not a block itself.
 */
public static DyeColor getColor(Block block) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Colorable)) return null;
        Colorable colorable = (Colorable) block.getBlockData();
        return colorable.getColor();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof Wool) {
        Wool wool = (Wool) data;
        return wool.getColor();
    }
    return null;
}
 
Example #2
Source File: ItemBuilder.java    From Crazy-Crates with MIT License 6 votes vote down vote up
public ItemBuilder addPattern(String stringPattern) {
    try {
        String[] split = stringPattern.split(":");
        for (PatternType pattern : PatternType.values()) {
            if (split[0].equalsIgnoreCase(pattern.name()) || split[0].equalsIgnoreCase(pattern.getIdentifier())) {
                DyeColor color = getDyeColor(split[1]);
                if (color != null) {
                    addPattern(new Pattern(color, pattern));
                }
                break;
            }
        }
    } catch (Exception e) {
    }
    return this;
}
 
Example #3
Source File: PlayerGroup.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the GroupColor matching the DyeColor or null if none exists.
 *
 * @param color the DyeColor to check
 * @return the GroupColor matching the DyeColor or null if none exists.
 */
public static Color getByDyeColor(DyeColor color) {
    for (Color groupColor : values()) {
        if (groupColor.dye == color) {
            return groupColor;
        }
    }
    return null;
}
 
Example #4
Source File: EntityWolfPet.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setCollarColor(DyeColor dc) {
    if (((IWolfPet) pet).isTamed()) {
        byte colour = dc.getWoolData();
        this.datawatcher.watch(20, colour);
    }
}
 
Example #5
Source File: BannerMetaSerializerImpl.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String serialize(BannerMeta bannerMeta) {
	if(bannerMeta == null) {
		return "";
	}

	StringBuilder builder = new StringBuilder();

	builder.append((bannerMeta.getBaseColor() == null ? DyeColor.BLACK : bannerMeta.getBaseColor()).name());

	if(bannerMeta.numberOfPatterns() > 0) {
		builder.append(':');
	}

	int index = 1;
	for(Pattern pattern : bannerMeta.getPatterns()) {
		builder.append(pattern.getColor().name());
		builder.append('-');
		builder.append(pattern.getPattern().getIdentifier());

		if(index < bannerMeta.numberOfPatterns()) {
			builder.append("|");
		}

		index++;
	}

	return builder.toString();
}
 
Example #6
Source File: ItemBuilder.java    From Crazy-Crates with MIT License 5 votes vote down vote up
private static DyeColor getDyeColor(String color) {
    if (color != null) {
        try {
            return DyeColor.valueOf(color.toUpperCase());
        } catch (Exception e) {
            try {
                String[] rgb = color.split(",");
                return DyeColor.getByColor(Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])));
            } catch (Exception ignore) {
            }
        }
    }
    return null;
}
 
Example #7
Source File: SheepShop.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void cycleSubType() {
	byte colorByte = color.getWoolData();
	colorByte += 1;
	color = DyeColor.getByWoolData(colorByte);
	if (color == null) {
		color = DyeColor.WHITE;
	}
	this.applySubType();
}
 
Example #8
Source File: CatShop.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
private short getSubItemData(Ocelot.Type catType) {
	switch (catType) {
	case BLACK_CAT:
		return DyeColor.BLACK.getWoolData();
	case RED_CAT:
		return DyeColor.RED.getWoolData();
	case SIAMESE_CAT:
		return DyeColor.SILVER.getWoolData();

	case WILD_OCELOT:
	default:
		return DyeColor.ORANGE.getWoolData();
	}
}
 
Example #9
Source File: XMLUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static DyeColor parseDyeColor(Attribute attr) throws InvalidXMLException {
    String name = attr.getValue().replace(" ", "_").toUpperCase();
    try {
        return DyeColor.valueOf(name);
    }
    catch(IllegalArgumentException e) {
        throw new InvalidXMLException("Invalid dye color '" + attr.getValue() + "'", attr);
    }
}
 
Example #10
Source File: Util.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a GUI button made of a wool.
 *
 * @param dc
 * @param name
 * @return
 */
public static ItemStack createButton(DyeColor dc, String name) {
    ItemStack i = new Wool(dc).toItemStack(1);
    ItemMeta im = i.getItemMeta();
    im.setDisplayName(name);
    i.setItemMeta(im);
    return i;
}
 
Example #11
Source File: WolfDisguise.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
/**
 * Creates an instance.
 * 
 * @since 5.7.1
 * @param collarColor The collar is invisible unless the state is {@link State#TAMED}.
 */
public WolfDisguise(boolean adult, State state, DyeColor collarColor, boolean sitting) {
	super(DisguiseType.WOLF, adult);
	this.state = state;
	this.collarColor = collarColor;
	this.sitting = sitting;
}
 
Example #12
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public Team getTeamByDyeColor(DyeColor color) {
  for (Team t : this.teams.values()) {
    if (t.getColor().getDyeColor().equals(color)) {
      return t;
    }
  }

  return null;
}
 
Example #13
Source File: WoolItemData.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
public static WoolItemData create(DyeColor color, ItemMeta meta) {
    return new WoolItemData(Preconditions.checkNotNull(color, "Null color").getWoolData(), meta);
}
 
Example #14
Source File: WoolObjective.java    From CardinalPGM with MIT License 4 votes vote down vote up
public DyeColor getColor() {
    return color;
}
 
Example #15
Source File: TNTSheepRegister.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ITNTSheep spawnCreature(
    final io.github.bedwarsrel.shop.Specials.TNTSheep specialItem,
    final Location location, final Player owner, Player target, final DyeColor color) {
  final TNTSheep sheep = new TNTSheep(location, target);

  ((CraftWorld) location.getWorld()).getHandle().addEntity(sheep, SpawnReason.CUSTOM);
  sheep.setPosition(location.getX(), location.getY(), location.getZ());
  ((CraftSheep) sheep.getBukkitEntity()).setColor(color);
  new BukkitRunnable() {

    @Override
    public void run() {

      TNTPrimed primedTnt = (TNTPrimed) location.getWorld()
          .spawnEntity(location.add(0.0, 1.0, 0.0), EntityType.PRIMED_TNT);
      ((CraftSheep) sheep.getBukkitEntity()).setPassenger(primedTnt);
      sheep.setTNT(primedTnt);
      try {
        Field sourceField = EntityTNTPrimed.class.getDeclaredField("source");
        sourceField.setAccessible(true);
        sourceField.set(((CraftTNTPrimed) primedTnt).getHandle(),
            ((CraftLivingEntity) owner).getHandle());
      } catch (Exception ex) {
        BedwarsRel.getInstance().getBugsnag().notify(ex);
        ex.printStackTrace();
      }
      sheep.getTNT().setYield((float) (sheep.getTNT().getYield()
          * BedwarsRel
          .getInstance().getConfig().getDouble("specials.tntsheep.explosion-factor", 1.0)));
      sheep.getTNT().setFuseTicks((int) Math.round(
          BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.fuse-time", 8) * 20));
      sheep.getTNT().setIsIncendiary(false);
      specialItem.getGame().getRegion().addRemovingEntity(sheep.getTNT());
      specialItem.getGame().getRegion().addRemovingEntity(sheep.getBukkitEntity());
      specialItem.updateTNT();
    }
  }.runTaskLater(BedwarsRel.getInstance(), 5L);

  return sheep;
}
 
Example #16
Source File: OwnedGoal.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public DyeColor getDyeColor() {
    return owner != null ? BukkitUtils.chatColorToDyeColor(owner.getColor())
                         : DyeColor.WHITE;
}
 
Example #17
Source File: SimpleGoal.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public DyeColor getDyeColor() {
    return DyeColor.WHITE;
}
 
Example #18
Source File: XMLUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static DyeColor parseDyeColor(Attribute attr, DyeColor def) throws InvalidXMLException {
    return attr == null ? def : parseDyeColor(attr);
}
 
Example #19
Source File: DyeItemData.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
public static DyeItemData create(DyeColor color) {
    return create(color, Bukkit.getItemFactory().getItemMeta(Material.INK_SACK));
}
 
Example #20
Source File: DyeItemData.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public DyeColor getColor() {
    return DyeColor.getByDyeData(getRawData());
}
 
Example #21
Source File: TropicalFishDisguise.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
public DyeColor getBodyColor() {
	return bodyColor;
}
 
Example #22
Source File: TNTSheep.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void spawn() {
    Sheep sheep = (Sheep) loc.getWorld().spawnEntity(loc, EntityType.SHEEP);
    TeamColor color = TeamColor.fromApiColor(team.getColor());
    Player target = MiscUtils.findTarget(game, player, maxTargetDistance);

    sheep.setColor(DyeColor.getByWoolData((byte) color.woolData));

    if (target == null) {
        player.sendMessage(i18n("specials_tntsheep_no_target_found"));
        sheep.remove();
        return;
    }

    entity = sheep;
    EntityUtils.makeMobAttackTarget(sheep, speed, followRange, 0)
    	.getTargetSelector().attackTarget(target);

    tnt = (TNTPrimed) loc.getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
    tnt.setFuseTicks(explosionTime);
    tnt.setIsIncendiary(false);
    sheep.addPassenger(tnt);

    game.registerSpecialItem(this);
    Main.registerGameEntity(sheep, (org.screamingsandals.bedwars.game.Game) game);
    Main.registerGameEntity(tnt, (org.screamingsandals.bedwars.game.Game) game);

    if (item.getAmount() > 1) {
    	item.setAmount(item.getAmount() - 1);
    } else {
    	player.getInventory().remove(item);
    }
    player.updateInventory();

    new BukkitRunnable() {

        @Override
        public void run() {
            tnt.remove();
            sheep.remove();
            game.unregisterSpecialItem(TNTSheep.this);
        }
    }.runTaskLater(Main.getInstance(), (explosionTime + 13));
}
 
Example #23
Source File: CraftBed.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DyeColor getColor() {
    return color;
}
 
Example #24
Source File: WoolItemData.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
public static WoolItemData create(DyeColor color) {
    return create(color, Bukkit.getItemFactory().getItemMeta(Material.WOOL));
}
 
Example #25
Source File: CraftWolf.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public void setCollarColor(DyeColor color) {
    getHandle().setCollarColor(EnumDyeColor.byMetadata(color.getWoolData()));
}
 
Example #26
Source File: TNTSheepRegister.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ITNTSheep spawnCreature(
    final io.github.bedwarsrel.shop.Specials.TNTSheep specialItem,
    final Location location, final Player owner, Player target, final DyeColor color) {
  final TNTSheep sheep = new TNTSheep(location, target);

  ((CraftWorld) location.getWorld()).getHandle().addEntity(sheep, SpawnReason.NATURAL);
  sheep.setPosition(location.getX(), location.getY(), location.getZ());
  ((CraftSheep) sheep.getBukkitEntity()).setColor(color);

  new BukkitRunnable() {

    @Override
    public void run() {
      TNTPrimed primedTnt = (TNTPrimed) location.getWorld()
          .spawnEntity(location.add(0.0, 1.0, 0.0), EntityType.PRIMED_TNT);
      ((CraftSheep) sheep.getBukkitEntity()).setPassenger(primedTnt);
      sheep.setTNT(primedTnt);

      try {
        Field sourceField = EntityTNTPrimed.class.getDeclaredField("source");
        sourceField.setAccessible(true);
        sourceField.set(((CraftTNTPrimed) primedTnt).getHandle(),
            ((CraftLivingEntity) owner).getHandle());
      } catch (Exception ex) {
        BedwarsRel.getInstance().getBugsnag().notify(ex);
        ex.printStackTrace();
      }

      sheep.getTNT().setYield((float) (sheep.getTNT().getYield()
          * BedwarsRel
          .getInstance().getConfig().getDouble("specials.tntsheep.explosion-factor", 1.0)));
      sheep.getTNT().setFuseTicks((int) Math.round(
          BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.fuse-time", 8) * 20));
      sheep.getTNT().setIsIncendiary(false);
      specialItem.getGame().getRegion().addRemovingEntity(sheep.getTNT());
      specialItem.getGame().getRegion().addRemovingEntity(sheep.getBukkitEntity());
      specialItem.updateTNT();
    }
  }.runTaskLater(BedwarsRel.getInstance(), 5L);

  return sheep;
}
 
Example #27
Source File: CraftWolf.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public DyeColor getCollarColor() {
    return DyeColor.getByWoolData((byte) getHandle().getCollarColor().getMetadata());
}
 
Example #28
Source File: SheepDyeWoolEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public SheepDyeWoolEvent(final Sheep sheep, final DyeColor color) {
    super(sheep);
    this.cancel = false;
    this.color = color;
}
 
Example #29
Source File: SheepShop.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void load(ConfigurationSection config) {
	super.load(config);
	this.color = DyeColor.getByWoolData((byte) config.getInt("color"));
}
 
Example #30
Source File: StainedClayItemData.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public StainedClayItemData withColor(DyeColor color) {
    return withRawData(Preconditions.checkNotNull(color, "Null color").getWoolData());
}