本文整理汇总了Java中org.bukkit.inventory.meta.BannerMeta类的典型用法代码示例。如果您正苦于以下问题:Java BannerMeta类的具体用法?Java BannerMeta怎么用?Java BannerMeta使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BannerMeta类属于org.bukkit.inventory.meta包,在下文中一共展示了BannerMeta类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: placeStanding
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
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;
}
示例2: change
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
@Override
public void change(Event e, Object[] delta, @NotNull Changer.ChangeMode mode) {
ItemStack i = item.getSingle(e);
if (i == null) {
return;
}
if (i.getType() == Material.BANNER || i.getType() == Material.SHIELD) {
BannerMeta meta = ((BannerMeta) i.getItemMeta());
switch (mode) {
case ADD:
Arrays.asList(((Pattern[]) delta)).forEach(meta::addPattern);
break;
case SET:
meta.setPatterns(Arrays.asList(((Pattern[]) delta)));
break;
case DELETE:
case RESET:
for (int j = 1; j <= meta.numberOfPatterns(); j++) {
meta.removePattern(j);
}
break;
}
i.setItemMeta(meta);
}
}
示例3: change
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
@Override
public void change(Event e, Object[] delta, @NotNull Changer.ChangeMode mode) {
ItemStack i = item.getSingle(e);
if (i == null) {
return;
}
if (i.getType() == Material.BANNER || i.getType() == Material.SHIELD) {
BannerMeta meta = ((BannerMeta) i.getItemMeta());
switch (mode) {
case SET:
Color c = (Color) delta[0];
meta.setBaseColor(c.getWoolColor());
break;
case RESET:
meta.setBaseColor(DyeColor.WHITE);
break;
}
i.setItemMeta(meta);
}
}
示例4: 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;
}
示例5: parse
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
public static ItemMeta parse(Element xml, ItemMeta source) {
if (source instanceof BannerMeta) {
return parseBanner(xml, (BannerMeta) source);
} else if (source instanceof BookMeta) {
return parseBook(xml, (BookMeta) source);
} else if (source instanceof EnchantmentStorageMeta) {
return parseEnchantmentStorage(xml, (EnchantmentStorageMeta) source);
} else if (source instanceof FireworkMeta) {
return parseFirework(xml, (FireworkMeta) source);
} else if (source instanceof FireworkEffectMeta) {
return parseFireworkEffect(xml, (FireworkEffectMeta) source);
} else if (source instanceof LeatherArmorMeta) {
return parseLeatherArmor(xml, (LeatherArmorMeta) source);
} else if (source instanceof MapMeta) {
return parseMap(xml, (MapMeta) source);
} else if (source instanceof PotionMeta) {
return parsePotion(xml, (PotionMeta) source);
} else if (source instanceof SkullMeta) {
return parseSkull(xml, (SkullMeta) source);
} else if (source instanceof SpawnEggMeta) {
return parseSpawnEgg(xml, (SpawnEggMeta) source);
}
return source;
}
示例6: Flag
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
/**
* Create a flag representing a banner item's layers. Does nothing if it is not
* a banner
*
* @param item
* the item. Does nothing if it isnt a banner
*/
@SuppressWarnings("deprecation")
public Flag(ItemStack item)
{
this(DyeColor.WHITE);
if(item.getType().equals(Material.BANNER))
{
BannerMeta bm = ((BannerMeta) item.getItemMeta());
baseColor = bm.getBaseColor();
for(int i = 0; i < bm.numberOfPatterns(); i++)
{
if(bm.getPattern(i).getPattern().equals(PatternType.BASE))
{
continue;
}
addLayer(new FlagLayer(bm.getPattern(i)));
}
}
}
示例7: saveBanner
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
static public void saveBanner(Player player, ItemStack banner) {
//只處理旗幟
if (!BannerUtil.isBanner(banner)) {
player.sendMessage(MessageUtil.format(true, "&c" + tl("io.save-failed")));
return;
}
//設定檔
String fileName = getFileName(player);
FileConfiguration config = KConfigManager.get(fileName);
//索引值(時間戳記,不會重複)
String key = String.valueOf(System.currentTimeMillis());
//旗幟資訊
BannerMeta bm = (BannerMeta) banner.getItemMeta();
//儲存
config.set(key + ".color", banner.getDurability());
List<String> patternList = new ArrayList<>();
for (Pattern pattern : bm.getPatterns()) {
patternList.add(pattern.getPattern().getIdentifier() + ":" + pattern.getColor().toString());
}
if (patternList.size() > 0) {
config.set(key + ".patterns", patternList);
}
KConfigManager.save(fileName);
//訊息
player.sendMessage(MessageUtil.format(true, "&a" + tl("io.save-success")));
}
示例8: executeCommand
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
@Override
public boolean executeCommand(CommandSender sender, Command cmd, String label, String[] args) {
BannerMaker bm = (BannerMaker) plugin;
Player player = (Player) sender;
ItemStack itemStack = bm.getVersionHandler().getItemInMainHand(player);
if (!BannerUtil.isBanner(itemStack)) {
player.sendMessage(MessageUtil.format(true, "&c" + tl("command.not-banner-hand")));
return true;
}
//複製旗幟,僅保留底色與樣式
BannerMeta originalBannerMeta = (BannerMeta) itemStack.getItemMeta();
KItemStack banner = new KItemStack(Material.BANNER)
.durability(itemStack.getDurability())
.setPatterns(originalBannerMeta.getPatterns());
//顯示旗幟
InventoryMenuUtil.showBannerInfo(player, banner);
return true;
}
示例9: bannerAdd
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
/**
* Adds {@link Pattern}s to this banner, assuming it is a banner.
* <p />
* <b>UNSAFE</b>
*
* @param patterns patterns to add
*
* @return this item builder instance, for chaining
*/
public ItemBuilder bannerAdd(Pattern... patterns) {
if (patterns == null) {
if (!this.failSilently) {
throw new IllegalArgumentException("patterns cannot be null.");
}
return this;
}
if (isBannerMeta()) {
try {
for (Pattern pattern : patterns) {
if (pattern != null) {
((BannerMeta) this.itemMeta).addPattern(pattern);
} else {
throw new NullPointerException("pattern element is null.");
}
}
} catch (Exception e) {
if (!this.failSilently) {
e.printStackTrace();
}
}
}
return this;
}
示例10: serializeBanner
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
/**
* A method to serialize banner meta to a JSONObject. Saves the base color, each pattern color, and each
* pattern type.
*
* @param banner The BannerMeta to serialize
* @return The JSONObject representation of the BannerMeta, or null if an exception occurred
*/
public static JSONObject serializeBanner(BannerMeta banner) {
try {
JSONObject root = new JSONObject();
if (banner.getBaseColor() != null)
root.put("base-color", banner.getBaseColor().getDyeData());
JSONArray colors = new JSONArray();
JSONArray patternTypes = new JSONArray();
for (Pattern pattern : banner.getPatterns()) {
colors.put(pattern.getColor().getDyeData());
patternTypes.put(pattern.getPattern().getIdentifier());
}
root.put("colors", colors);
root.put("pattern-types", patternTypes);
return root;
} catch (JSONException ex) {
ex.printStackTrace();
return null;
}
}
示例11: 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;
}
}
示例12: processMeta
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
@Override
public void processMeta(Player player, ItemMeta m) {
super.processMeta(player, m);
BannerMeta meta = (BannerMeta) m;
meta.setBaseColor(baseColor);
meta.setPatterns(patterns);
}
示例13: createBanner
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
public static ItemStack createBanner(String name, List<String> lore, DyeColor color){
ItemStack banner = new ItemStack(Material.BANNER);
BannerMeta itemMeta = (BannerMeta) banner.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ATTRIBUTES,
ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_UNBREAKABLE);
ArrayList<String> colorLore = new ArrayList<>();
if (lore != null) {
lore.forEach(str -> colorLore.add(Utils.colorize(str)));
itemMeta.setLore(colorLore);
}
itemMeta.setBaseColor(color);
itemMeta.setDisplayName(name);
banner.setItemMeta(itemMeta);
return banner;
}
示例14: setBanner
import org.bukkit.inventory.meta.BannerMeta; //导入依赖的package包/类
/**
* @param banner
* the banner to set
*/
public void setBanner(ItemStack banner) {
if (banner.getType() != Material.BANNER && banner.getType() != Material.SHIELD) {
return;
}
this.banner = (BannerMeta) banner.getItemMeta();
bannerColor = banner.getDurability();
}
示例15: 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};
}