本文整理汇总了Java中org.bukkit.inventory.meta.BannerMeta.addPattern方法的典型用法代码示例。如果您正苦于以下问题:Java BannerMeta.addPattern方法的具体用法?Java BannerMeta.addPattern怎么用?Java BannerMeta.addPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.meta.BannerMeta
的用法示例。
在下文中一共展示了BannerMeta.addPattern方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseMncPattern
import org.bukkit.inventory.meta.BannerMeta; //导入方法依赖的package包/类
public static BannerMeta parseMncPattern(@NotNull String mnc) {
if (mnc.matches("[a-p]a([a-p][b-zA-M])+")) {
List<String> groups = StringUtils.sizedSplitString(mnc, 2, true);
BannerMeta meta = emptyBannerMeta();
meta.setBaseColor(colorFromMnc(mnc.charAt(0)));
for (String str : groups.subList(1, groups.size())) {
if (!str.isEmpty()) {
meta.addPattern(new Pattern(colorFromMnc(str.toCharArray()[0]),
patternTypeFromMnc(str.toCharArray()[1])
));
}
}
return meta;
}
return null;
}
示例2: getBannerMeta
import org.bukkit.inventory.meta.BannerMeta; //导入方法依赖的package包/类
/**
* 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 or null if an exception occurs
*/
public static BannerMeta getBannerMeta(JSONObject json) {
try {
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.getJSONArray("colors");
JSONArray patternTypes = json.getJSONArray("pattern-types");
for (int i = 0; i < colors.length(); i++) {
dummy.addPattern(new Pattern(DyeColor.getByDyeData(Integer.valueOf((int) colors.get(i)).byteValue()),
PatternType.getByIdentifier(patternTypes.getString(i))));
}
return dummy;
} catch (JSONException ex) {
ex.printStackTrace();
return null;
}
}
示例3: get
import org.bukkit.inventory.meta.BannerMeta; //导入方法依赖的package包/类
@NotNull
@Override
protected ItemStack[] get(Event event) {
ItemStack banner = new ItemStack(type);
BannerMeta meta = (BannerMeta) banner.getItemMeta();
meta.setBaseColor(CollectionUtils.getRandom(DyeColor.values()));
for (int i = 0; i < new Random().nextInt(7); i++)
meta.addPattern(new Pattern(CollectionUtils.getRandom(DyeColor.values()),
CollectionUtils.getRandom(PatternType.values())
));
banner.setItemMeta(meta);
return new ItemStack[]{banner};
}
示例4: loadBanner
import org.bukkit.inventory.meta.BannerMeta; //导入方法依赖的package包/类
private static ItemStack loadBanner(Player player, String key) {
//設定檔
String fileName = getFileName(player);
FileConfiguration config = KConfigManager.get(fileName);
//檢查是否為物品
ItemStack banner = null;
//檢查是否為正確格式
if (config.isInt(key + ".color") && (!config.contains(key + ".patterns") || config.isList(key + ".patterns"))) {
//嘗試以新格式讀取
try {
//建立旗幟
banner = new ItemStack(Material.BANNER, 1, (short) config.getInt(key + ".color"));
BannerMeta bm = (BannerMeta) banner.getItemMeta();
//新增Patterns
if (config.contains(key + ".patterns")) {
List<String> patternsList = config.getStringList(key + ".patterns");
for (String str : patternsList) {
String strPattern = str.split(":")[0];
String strColor = str.split(":")[1];
Pattern pattern = new Pattern(DyeColor.valueOf(strColor), PatternType.getByIdentifier(strPattern));
bm.addPattern(pattern);
}
banner.setItemMeta(bm);
}
//將key藏於Lore
bm.setLore(Collections.singletonList(HiddenStringUtil.encodeString(key)));
banner.setItemMeta(bm);
} catch (Exception e) {
banner = null;
}
}
//只處理旗幟
if (!BannerUtil.isBanner(banner)) {
return null;
}
return banner;
}
示例5: getRandomMeta
import org.bukkit.inventory.meta.BannerMeta; //导入方法依赖的package包/类
/**
* 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(Material.BANNER);
meta.setBaseColor(randomDyeColor());
for(int i = NumberUtils.randInt(0, PatternType.values().length) + 2; i > 0; i--) {
meta.addPattern(new Pattern(randomDyeColor(), randomPatternType()));
}
return meta;
}
示例6: getBannerMeta
import org.bukkit.inventory.meta.BannerMeta; //导入方法依赖的package包/类
/**
* 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(Material.BANNER);
meta.setBaseColor(banner.getBaseColor());
for(Pattern pattern : banner.getPatterns()) {
meta.addPattern(pattern);
}
return meta;
}
示例7: deserialize
import org.bukkit.inventory.meta.BannerMeta; //导入方法依赖的package包/类
@Override
public BannerMeta deserialize(String string) {
BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(Material.BANNER);
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;
}
示例8: CustomBanner
import org.bukkit.inventory.meta.BannerMeta; //导入方法依赖的package包/类
public CustomBanner(DyeColor color, Pattern... patterns) {
super(Material.BANNER);
BannerMeta meta = (BannerMeta) getItemMeta();
meta.setBaseColor(color);
for (Pattern pattern: patterns) {
meta.addPattern(pattern);
}
setItemMeta(meta);
}