Java Code Examples for org.bukkit.inventory.meta.BannerMeta#setBaseColor()

The following examples show how to use org.bukkit.inventory.meta.BannerMeta#setBaseColor() . 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: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets random banner meta
 *
 * @return banner meta
 */
public static BannerMeta getRandomMeta() {
	if(ConfigManager.getServerVersion().isOlderThan(ConfigManager.ServerVersion.MINECRAFT_1_8_R2)) {
		return null;
	}

	BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(CompatibilityUtils.Mat.WHITE_BANNER.get());
	meta.setBaseColor(randomDyeColor());

	for(int i = NumberUtils.randInt(0, PatternType.values().length) + 2; i > 0; i--) {
		meta.addPattern(new Pattern(randomDyeColor(), randomPatternType()));
	}

	return meta;
}
 
Example 2
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Turns a banner into banner meta
 *
 * @param banner banner block
 * @return banner meta
 */
public static BannerMeta getBannerMeta(Banner banner) {
	if(ConfigManager.getServerVersion().isOlderThan(ConfigManager.ServerVersion.MINECRAFT_1_8_R2)) {
		return null;
	}

	BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(CompatibilityUtils.Mat.WHITE_BANNER.get());

	meta.setBaseColor(banner.getBaseColor());
	for(Pattern pattern : banner.getPatterns()) {
		meta.addPattern(pattern);
	}

	return meta;
}
 
Example 3
Source File: Materials.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static BannerMeta getItemMeta(Banner block) {
  BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(Material.BANNER);
  meta.setBaseColor(block.getBaseColor());
  meta.setPatterns(block.getPatterns());
  return meta;
}
 
Example 4
Source File: Banners.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static BannerMeta getItemMeta(Banner block) {
    BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(Material.BANNER);
    meta.setBaseColor(block.getBaseColor());
    meta.setPatterns(block.getPatterns());
    return meta;
}
 
Example 5
Source File: BannerMetaSerializerImpl.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BannerMeta deserialize(String string) {
	BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(CompatibilityUtils.Mat.WHITE_BANNER.get());

	if(string == null || string.isEmpty()) {
		return meta;
	}

	String baseColorString;
	String patternsString;

	if(StringUtils.contains(string, ':')) {
		String[] baseSplit = StringUtils.split(string, ':');
		baseColorString = baseSplit[0];
		patternsString = baseSplit[1];
	}
	else {
		baseColorString = string;
		patternsString = "";
	}

	meta.setBaseColor(DyeColor.valueOf(baseColorString));

	if(!patternsString.isEmpty()) {
		String[] patternsSplit;

		if(StringUtils.contains(patternsString, '|')) {
			patternsSplit = StringUtils.split(patternsString, '|');
		}
		else {
			patternsSplit = new String[]{
					patternsString
			};
		}

		for(String patternString : patternsSplit) {
			String[] patternSplit = StringUtils.split(patternString, '-');

			meta.addPattern(new Pattern(DyeColor.valueOf(patternSplit[0]), PatternType.getByIdentifier(patternSplit[1])));
		}
	}

	return meta;
}
 
Example 6
Source File: CustomBanner.java    From CS-CoreLib with GNU General Public License v3.0 3 votes vote down vote up
public CustomBanner(DyeColor color, Pattern... patterns) {
	super(MaterialHook.parse("WHITE_BANNER", "BANNER"));
	
	BannerMeta meta = (BannerMeta) getItemMeta();
	
	meta.setBaseColor(color);
	
	for (Pattern pattern: patterns) {
		meta.addPattern(pattern);
	}
	
	setItemMeta(meta);
}