org.bukkit.block.banner.Pattern Java Examples
The following examples show how to use
org.bukkit.block.banner.Pattern.
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 |
/** * @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: ItemBuilder.java From Crazy-Crates with MIT License | 6 votes |
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: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override void applyToItem(NBTTagCompound tag) { super.applyToItem(tag); NBTTagCompound entityTag = new NBTTagCompound(); if (base != null) { entityTag.setInteger(BASE.NBT, base.getDyeData()); } NBTTagList newPatterns = new NBTTagList(); for (Pattern p : patterns) { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger(COLOR.NBT, p.getColor().getDyeData()); compound.setString(PATTERN.NBT, p.getPattern().getIdentifier()); newPatterns.appendTag(compound); } entityTag.setTag(PATTERNS.NBT, newPatterns); tag.setTag("BlockEntityTag", entityTag); }
Example #4
Source File: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 6 votes |
CraftMetaBanner(Map<String, Object> map) { super(map); String baseStr = SerializableMeta.getString(map, BASE.BUKKIT, true); if (baseStr != null) { base = DyeColor.valueOf(baseStr); } Iterable<?> rawPatternList = SerializableMeta.getObject(Iterable.class, map, PATTERNS.BUKKIT, true); if (rawPatternList == null) { return; } for (Object obj : rawPatternList) { if (!(obj instanceof Pattern)) { throw new IllegalArgumentException("Object in pattern list is not valid. " + obj.getClass()); } addPattern((Pattern) obj); } }
Example #5
Source File: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 6 votes |
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 #6
Source File: CraftBanner.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public void applyTo(TileEntityBanner banner) { super.applyTo(banner); banner.baseColor = EnumDyeColor.byDyeDamage(base.getDyeData()); NBTTagList newPatterns = new NBTTagList(); for (Pattern p : patterns) { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("Color", p.getColor().getDyeData()); compound.setString("Pattern", p.getPattern().getIdentifier()); newPatterns.appendTag(compound); } banner.patterns = newPatterns; }
Example #7
Source File: ItemUtils.java From ChestCommands with GNU General Public License v3.0 | 5 votes |
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 #8
Source File: DeprecatedMethodUtil.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * 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 #9
Source File: BannerMetaSerializerImpl.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
@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 #10
Source File: BannerUtils.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
/** * 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 #11
Source File: BannerUtils.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
/** * 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 #12
Source File: DeprecatedMethodUtil.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * 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 #13
Source File: BannerBuilderTest.java From Chimera with MIT License | 5 votes |
@Test void pattern() { var first = new Pattern(RED, BORDER); var second = new Pattern(RED, FLOWER); BannerBuilder.of(WATER).self().patterns(first).patterns(Set.of(second)); verify(meta).addPattern(first); verify(meta).addPattern(second); }
Example #14
Source File: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 5 votes |
CraftMetaBanner(CraftMetaItem meta) { super(meta); if (!(meta instanceof CraftMetaBanner)) { return; } CraftMetaBanner banner = (CraftMetaBanner) meta; base = banner.base; patterns = new ArrayList<Pattern>(banner.patterns); }
Example #15
Source File: CraftBanner.java From Kettle with GNU General Public License v3.0 | 5 votes |
@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 #16
Source File: CraftBanner.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public void setPatterns(List<Pattern> patterns) { this.patterns = new ArrayList<Pattern>(patterns); }
Example #17
Source File: Icon.java From ChestCommands with GNU General Public License v3.0 | 4 votes |
public void setBannerPatterns(List<Pattern> bannerPatterns) { this.bannerPatterns = bannerPatterns; }
Example #18
Source File: Icon.java From ChestCommands with GNU General Public License v3.0 | 4 votes |
public List<Pattern> getBannerPatterns() { return bannerPatterns; }
Example #19
Source File: BannerBlock.java From askyblock with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("deprecation") public boolean prep(Map<String, Tag> tileData) { // Format for banner is: // Patterns = List of patterns // id = String "BannerBlock" // Base = Int color // Then the location // z = Int // y = Int // x = Int try { // Do the base color int baseColor = 15 - ((IntTag) tileData.get("Base")).getValue(); // //ASkyBlock.getPlugin().getLogger().info("Base value = " + // baseColor); // baseColor green = 10 bannerBaseColor = DyeColor.getByDyeData((byte) baseColor); // Do the patterns (no idea if this will work or not) bannerPattern = new ArrayList<Pattern>(); ListTag patterns = (ListTag) tileData.get("Patterns"); if (patterns != null) { for (Tag pattern : patterns.getValue()) { // ASkyBlock.getPlugin().getLogger().info("pattern = " + // pattern); // Translate pattern to PatternType if (pattern instanceof CompoundTag) { CompoundTag patternColor = (CompoundTag) pattern; // The tag is made up of pattern (String) and color // (int) Map<String, Tag> patternValue = patternColor.getValue(); StringTag mark = (StringTag) patternValue.get("Pattern"); Integer markColor = 15 - ((IntTag) patternValue.get("Color")).getValue(); // ASkyBlock.getPlugin().getLogger().info("mark = " + // mark.getValue()); // ASkyBlock.getPlugin().getLogger().info("color = " + // markColor); DyeColor dColor = DyeColor.getByDyeData(markColor.byteValue()); // ASkyBlock.getPlugin().getLogger().info(" dye color = " // + dColor.toString()); if (patternKey.containsKey(mark.getValue())) { Pattern newPattern = new Pattern(dColor, patternKey.get(mark.getValue())); bannerPattern.add(newPattern); } } } } } catch (Exception e) { e.printStackTrace(); } return true; }
Example #20
Source File: BannerMetaSerializerImpl.java From NovaGuilds with GNU General Public License v3.0 | 4 votes |
@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 #21
Source File: ItemBuilder.java From Crazy-Crates with MIT License | 4 votes |
public ItemBuilder setPatterns(List<Pattern> patterns) { this.patterns = patterns; return this; }
Example #22
Source File: ItemBuilder.java From Crazy-Crates with MIT License | 4 votes |
public ItemBuilder addPattern(Pattern pattern) { patterns.add(pattern); return this; }
Example #23
Source File: ItemBuilder.java From Crazy-Crates with MIT License | 4 votes |
public List<Pattern> getPatterns() { return patterns; }
Example #24
Source File: ItemBuilder.java From TabooLib with MIT License | 4 votes |
public ItemBuilder banner(Pattern... patterns) { if (itemMeta instanceof BannerMeta) { java.util.Arrays.stream(patterns).forEach(pattern -> ((BannerMeta) itemMeta).addPattern(pattern)); } return this; }
Example #25
Source File: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public void setPattern(int i, Pattern pattern) { patterns.set(i, pattern); }
Example #26
Source File: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public Pattern removePattern(int i) { return patterns.remove(i); }
Example #27
Source File: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public Pattern getPattern(int i) { return patterns.get(i); }
Example #28
Source File: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public void setPatterns(List<Pattern> patterns) { this.patterns = new ArrayList<Pattern>(patterns); }
Example #29
Source File: CraftMetaBanner.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public List<Pattern> getPatterns() { return new ArrayList<Pattern>(patterns); }
Example #30
Source File: CraftBanner.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public List<Pattern> getPatterns() { return new ArrayList<Pattern>(patterns); }