Java源码示例:org.bukkit.inventory.meta.BannerMeta

示例1
/**
 * @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));
            }
        }
    });
}
 
示例2
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;
}
 
示例3
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);
}
 
示例4
/**
 * 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;
}
 
示例5
/**
 * 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);
}
 
示例6
/**
 * 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);
}
 
示例7
/**
 * 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;
}
 
示例8
/**
 * 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;
}
 
示例9
@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();
}
 
示例10
static BannerMeta getItemMeta(Banner block) {
  BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(Material.BANNER);
  meta.setBaseColor(block.getBaseColor());
  meta.setPatterns(block.getPatterns());
  return meta;
}
 
示例11
static void applyToBlock(Banner block, BannerMeta meta) {
  block.setBaseColor(meta.getBaseColor());
  block.setPatterns(meta.getPatterns());
}
 
示例12
public BannerMeta getBannerMeta() {
  return bannerMeta;
}
 
示例13
private BannerInfo(Location location, BannerMeta meta, ItemStack item, AngleProvider yawProvider) {
    this.location = location;
    this.meta = meta;
    this.item = item;
    this.yawProvider = yawProvider;
}
 
示例14
public BannerMeta getBannerMeta() {
    return bannerInfo.meta;
}
 
示例15
public static BannerMeta getItemMeta(Banner block) {
    BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(Material.BANNER);
    meta.setBaseColor(block.getBaseColor());
    meta.setPatterns(block.getPatterns());
    return meta;
}
 
示例16
public static void applyToBlock(Banner block, BannerMeta meta) {
    block.setBaseColor(meta.getBaseColor());
    block.setPatterns(meta.getPatterns());
}
 
示例17
@Override
public BannerMeta getBannerMeta() {
	return bannerMeta;
}
 
示例18
@Override
public void setBannerMeta(BannerMeta bannerMeta) {
	this.bannerMeta = bannerMeta;
	setChanged();
}
 
示例19
@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;
}
 
示例20
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);
}
 
示例21
/**
 * Gets banner meta
 *
 * @return banner meta
 */
BannerMeta getBannerMeta();
 
示例22
/**
 * Sets banner meta
 *
 * @param bannerMeta the meta
 */
void setBannerMeta(BannerMeta bannerMeta);
 
示例23
/**
 * Serializes banner meta into a string
 *
 * @param bannerMeta banner meta
 * @return serialized meta
 */
String serialize(BannerMeta bannerMeta);
 
示例24
/**
 * Deserializes meta from a string
 *
 * @param string serialized meta
 * @return banner meta
 */
BannerMeta deserialize(String string);
 
示例25
/**
 * 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;
}