org.bukkit.inventory.meta.BannerMeta Java Examples

The following examples show how to use org.bukkit.inventory.meta.BannerMeta. 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: Dyer.java    From TrMenu with MIT License 6 votes vote down vote up
/**
 * @author Bkm016
 */
public static void setBanner(BannerMeta itemMeta, List<String> patterns) {
    patterns.forEach(pattern -> {
        String[] type = pattern.split(" ");
        if (type.length == 1) {
            try {
                itemMeta.setBaseColor(DyeColor.valueOf(type[0].toUpperCase()));
            } catch (Exception ignored) {
                itemMeta.setBaseColor(DyeColor.BLACK);
            }
        } else if (type.length == 2) {
            try {
                itemMeta.addPattern(new Pattern(DyeColor.valueOf(type[0].toUpperCase()), PatternType.valueOf(type[1].toUpperCase())));
            } catch (Exception e) {
                itemMeta.addPattern(new Pattern(DyeColor.BLACK, PatternType.BASE));
            }
        }
    });
}
 
Example #2
Source File: Banners.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public static boolean placeStanding(Location location, BannerMeta meta) {
    Block block = location.getBlock();
    block.setType(Material.STANDING_BANNER, false);

    final BlockState state = block.getState();
    if(state instanceof Banner) {
        Banner banner = (Banner) block.getState();
        applyToBlock(banner, meta);

        org.bukkit.material.Banner material = (org.bukkit.material.Banner) banner.getData();
        material.setFacingDirection(BlockFaces.yawToFace(location.getYaw()));
        banner.setData(material);
        banner.update(true);
        return true;
    }
    return false;
}
 
Example #3
Source File: Materials.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
static void placeStanding(Location location, BannerMeta meta) {
  Block block = location.getBlock();
  block.setType(Material.STANDING_BANNER);

  Banner banner = (Banner) block.getState();
  applyToBlock(banner, meta);

  org.bukkit.material.Banner material = (org.bukkit.material.Banner) banner.getData();
  material.setFacingDirection(BlockFaces.yawToFace(location.getYaw()));
  banner.setData(material);
  banner.update(true);
}
 
Example #4
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 #5
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 #6
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies meta to a shield
 *
 * @param itemStack  shield item
 * @param bannerMeta banner meta
 * @return shield item
 */
public static ItemStack applyMeta(ItemStack itemStack, BannerMeta bannerMeta) {
	if(itemStack.getType() != Material.SHIELD && itemStack.getType() != CompatibilityUtils.Mat.WHITE_BANNER.get()) {
		throw new IllegalArgumentException("Passed ItemStack is not a shield nor a banner");
	}

	ItemMeta meta = itemStack.getItemMeta();
	BlockStateMeta blockStateMeta = (BlockStateMeta) meta;
	Banner banner = (Banner) blockStateMeta.getBlockState();
	applyMeta(banner, bannerMeta);
	banner.update();
	blockStateMeta.setBlockState(banner);
	itemStack.setItemMeta(blockStateMeta);
	return itemStack;
}
 
Example #7
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serializes banner meta into a string
 *
 * @param bannerMeta banner meta
 * @return serialized meta
 */
public static String serialize(BannerMeta bannerMeta) {
	if(ConfigManager.getServerVersion().isOlderThan(ConfigManager.ServerVersion.MINECRAFT_1_8_R2)) {
		return "";
	}

	return getSerializer().serialize(bannerMeta);
}
 
Example #8
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deserializes a string to banner meta
 *
 * @param string serialized meta
 * @return banner meta
 */
public static BannerMeta deserialize(String string) {
	if(ConfigManager.getServerVersion().isOlderThan(ConfigManager.ServerVersion.MINECRAFT_1_8_R2)) {
		return null;
	}

	return getSerializer().deserialize(string);
}
 
Example #9
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 #10
Source File: Materials.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static void applyToBlock(Banner block, BannerMeta meta) {
  block.setBaseColor(meta.getBaseColor());
  block.setPatterns(meta.getPatterns());
}
 
Example #11
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 #12
Source File: NovaGuildImpl.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setBannerMeta(BannerMeta bannerMeta) {
	this.bannerMeta = bannerMeta;
	setChanged();
}
 
Example #13
Source File: NovaGuildImpl.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BannerMeta getBannerMeta() {
	return bannerMeta;
}
 
Example #14
Source File: Banners.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void applyToBlock(Banner block, BannerMeta meta) {
    block.setBaseColor(meta.getBaseColor());
    block.setPatterns(meta.getPatterns());
}
 
Example #15
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 #16
Source File: Flag.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public BannerMeta getBannerMeta() {
    return bannerInfo.meta;
}
 
Example #17
Source File: Flag.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
private BannerInfo(Location location, BannerMeta meta, ItemStack item, AngleProvider yawProvider) {
    this.location = location;
    this.meta = meta;
    this.item = item;
    this.yawProvider = yawProvider;
}
 
Example #18
Source File: Flag.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public BannerMeta getBannerMeta() {
  return bannerMeta;
}
 
Example #19
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 #20
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);
}
 
Example #21
Source File: BannerMetaSerializer.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Serializes banner meta into a string
 *
 * @param bannerMeta banner meta
 * @return serialized meta
 */
String serialize(BannerMeta bannerMeta);
 
Example #22
Source File: BannerMetaSerializer.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Deserializes meta from a string
 *
 * @param string serialized meta
 * @return banner meta
 */
BannerMeta deserialize(String string);
 
Example #23
Source File: NovaGuild.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets banner meta
 *
 * @param bannerMeta the meta
 */
void setBannerMeta(BannerMeta bannerMeta);
 
Example #24
Source File: NovaGuild.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets banner meta
 *
 * @return banner meta
 */
BannerMeta getBannerMeta();
 
Example #25
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Applies meta to a banner
 *
 * @param banner banner block
 * @param meta   banner meta
 * @return banner block
 */
public static Banner applyMeta(Banner banner, BannerMeta meta) {
	banner.setBaseColor(meta.getBaseColor());
	banner.setPatterns(meta.getPatterns());
	return banner;
}