org.bukkit.block.banner.PatternType Java Examples

The following examples show how to use org.bukkit.block.banner.PatternType. 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: CraftMetaBanner.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
CraftMetaBanner(NBTTagCompound tag) {
    super(tag);

    if (!tag.hasKey("BlockEntityTag")) {
        return;
    }

    NBTTagCompound entityTag = tag.getCompoundTag("BlockEntityTag");

    base = entityTag.hasKey(BASE.NBT) ? DyeColor.getByDyeData((byte) entityTag.getInteger(BASE.NBT)) : null;

    if (entityTag.hasKey(PATTERNS.NBT)) {
        NBTTagList patterns = entityTag.getTagList(PATTERNS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
        for (int i = 0; i < Math.min(patterns.tagCount(), 20); i++) {
            NBTTagCompound p = patterns.getCompoundTagAt(i);
            this.patterns.add(new Pattern(DyeColor.getByDyeData((byte) p.getInteger(COLOR.NBT)), PatternType.getByIdentifier(p.getString(PATTERN.NBT))));
        }
    }
}
 
Example #3
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 #4
Source File: CraftBanner.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void load(TileEntityBanner banner) {
    super.load(banner);

    base = DyeColor.getByDyeData((byte) banner.baseColor.getDyeDamage());
    patterns = new ArrayList<Pattern>();

    if (banner.patterns != null) {
        for (int i = 0; i < banner.patterns.tagCount(); i++) {
            NBTTagCompound p = (NBTTagCompound) banner.patterns.get(i);
            patterns.add(new Pattern(DyeColor.getByDyeData((byte) p.getInteger("Color")), PatternType.getByIdentifier(p.getString("Pattern"))));
        }
    }
}
 
Example #5
Source File: DeprecatedMethodUtil.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A method to deserialize a BannerMeta object from a JSONObject. This method assumes that the JSONArrays containing
 * the colors and pattern types are the same length.
 *
 * @param json The JSONObject of the BannerMeta to deserialize
 * @return The BannerMeta
 */
public static BannerMeta getBannerMeta(JsonObject json) {
    BannerMeta dummy = (BannerMeta) new ItemStack(Material.BANNER).getItemMeta();
    if (json.has("base-color"))
        dummy.setBaseColor(DyeColor.getByDyeData(Byte.parseByte("" + json.get("base-color"))));

    JsonArray colors = json.getAsJsonArray("colors");
    JsonArray patternTypes = json.getAsJsonArray("pattern-types");
    for (int i = 0; i < colors.size() - 1; i++) {
        dummy.addPattern(new Pattern(DyeColor.getByDyeData(Integer.valueOf(colors.get(i).getAsInt()).byteValue()),
                PatternType.getByIdentifier(patternTypes.get(i).getAsString())));
    }

    return dummy;
}
 
Example #6
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 #7
Source File: DeprecatedMethodUtil.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A method to deserialize a BannerMeta object from a JSONObject. This method assumes that the JSONArrays containing
 * the colors and pattern types are the same length.
 *
 * @param json The JSONObject of the BannerMeta to deserialize
 * @return The BannerMeta
 */
public static BannerMeta getBannerMeta(JsonObject json) {
    BannerMeta dummy = (BannerMeta) new ItemStack(Material.BANNER).getItemMeta();
    if (json.has("base-color"))
        dummy.setBaseColor(DyeColor.getByDyeData(Byte.parseByte("" + json.get("base-color"))));

    JsonArray colors = json.getAsJsonArray("colors");
    JsonArray patternTypes = json.getAsJsonArray("pattern-types");
    for (int i = 0; i < colors.size() - 1; i++) {
        dummy.addPattern(new Pattern(DyeColor.getByDyeData(Integer.valueOf(colors.get(i).getAsInt()).byteValue()),
                PatternType.getByIdentifier(patternTypes.get(i).getAsString())));
    }

    return dummy;
}
 
Example #8
Source File: ItemUtils.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
public static List<Pattern> parseBannerPatternList(List<String> input) throws FormatException {
	List<Pattern> patterns = new ArrayList<Pattern>();
	for (String str : input) {
		String[] split = str.split(":");
		if (split.length != 2) {
			throw new FormatException("it must be in the format \"pattern:color\".");
		}
		try {
			patterns.add(new Pattern(parseDyeColor(split[1]), PatternType.valueOf(split[0].toUpperCase())));
		} catch (IllegalArgumentException e) {
			throw new FormatException("it must be a valid pattern type.");
		}
	}
	return patterns;
}
 
Example #9
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 #10
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets random pattern type
 *
 * @return pattern type
 */
protected static PatternType randomPatternType() {
	return PatternType.values()[NumberUtils.randInt(0, PatternType.values().length - 1)];
}