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;
}
java类org.bukkit.inventory.meta.BannerMeta的实例源码
Banners.java 文件源码
项目:ProjectAres
阅读 17
收藏 0
点赞 0
评论 0
SExprItemLayers.java 文件源码
项目:QuarSK
阅读 29
收藏 0
点赞 0
评论 0
@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);
}
}
SExprItemBaseColor.java 文件源码
项目:QuarSK
阅读 26
收藏 0
点赞 0
评论 0
@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);
}
}
BannerUtils.java 文件源码
项目:QuarSK
阅读 28
收藏 0
点赞 0
评论 0
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;
}
XMLItemMeta.java 文件源码
项目:Arcade2
阅读 20
收藏 0
点赞 0
评论 0
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;
}
Flag.java 文件源码
项目:Phantom
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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)));
}
}
}
IOUtil.java 文件源码
项目:BannerMaker
阅读 23
收藏 0
点赞 0
评论 0
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")));
}
HandCommand.java 文件源码
项目:BannerMaker
阅读 19
收藏 0
点赞 0
评论 0
@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;
}
ItemBuilder.java 文件源码
项目:SupaCommons
阅读 22
收藏 0
点赞 0
评论 0
/**
* 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;
}
BannerSerialization.java 文件源码
项目:NexusInventory
阅读 22
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
BannerSerialization.java 文件源码
项目:NexusInventory
阅读 24
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
BannerCustomItem.java 文件源码
项目:uppercore
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void processMeta(Player player, ItemMeta m) {
super.processMeta(player, m);
BannerMeta meta = (BannerMeta) m;
meta.setBaseColor(baseColor);
meta.setPatterns(patterns);
}
ItemUtil.java 文件源码
项目:WC
阅读 27
收藏 0
点赞 0
评论 0
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;
}
LegalEntity.java 文件源码
项目:FactionsXL
阅读 21
收藏 0
点赞 0
评论 0
/**
* @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();
}
ExprRandomBanner.java 文件源码
项目:QuarSK
阅读 20
收藏 0
点赞 0
评论 0
@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};
}
SExprItemLayers.java 文件源码
项目:QuarSK
阅读 24
收藏 0
点赞 0
评论 0
@Nullable
@Override
protected Pattern[] get(Event e) {
ItemStack i = item.getSingle(e);
if (i == null) {
return null;
}
if (i.getType() == Material.BANNER || i.getType() == Material.SHIELD) {
return ((BannerMeta) i.getItemMeta()).getPatterns().stream().toArray(Pattern[]::new);
}
return null;
}
ExprItemOfBannerBlock.java 文件源码
项目:QuarSK
阅读 20
收藏 0
点赞 0
评论 0
@Override
public ItemStack convert(Block block) {
if (block.getType() == Material.STANDING_BANNER || block.getType() == Material.WALL_BANNER) {
Banner banner = (Banner) block.getState();
ItemStack item = new ItemStack(Material.BANNER);
BannerMeta meta = (BannerMeta) item.getItemMeta();
meta.setPatterns(banner.getPatterns());
meta.setBaseColor(banner.getBaseColor());
item.setItemMeta(meta);
return item;
}
return null;
}
ExprBannerOrShieldWithLayers.java 文件源码
项目:QuarSK
阅读 35
收藏 0
点赞 0
评论 0
@Nullable
@Override
protected ItemStack[] get(Event e) {
Color c = color.getSingle(e);
if (c == null)
return null;
ItemStack returnItem = new ItemStack(mat);
BannerMeta meta = ((BannerMeta) returnItem.getItemMeta());
meta.setPatterns(Arrays.asList(patterns.getAll(e)));
meta.setBaseColor(c.getWoolColor());
returnItem.setItemMeta(meta);
return new ItemStack[]{returnItem};
}
ExprBannerItemToMnc.java 文件源码
项目:QuarSK
阅读 20
收藏 0
点赞 0
评论 0
@Nullable
@Override
protected String[] get(Event e) {
ItemStack i = item.getSingle(e);
if (i == null) {
return null;
}
if (i.getType() == Material.BANNER || i.getType() == Material.SHIELD) {
return new String[]{BannerUtils.toMncPattern((BannerMeta) i.getItemMeta())};
}
return null;
}
EffApplyBannerItemToBlock.java 文件源码
项目:QuarSK
阅读 21
收藏 0
点赞 0
评论 0
@Override
protected void execute(Event e) {
ItemStack i = item.getSingle(e);
Block b = block.getSingle(e);
if (i == null || b == null) {
return;
}
if ((i.getType() == Material.BANNER || i.getType() == Material.SHIELD) && b.getType() == Material.BANNER) {
BannerMeta itemMeta = ((BannerMeta) i.getItemMeta());
Banner blockMeta = ((Banner) b.getState());
blockMeta.setPatterns(itemMeta.getPatterns());
blockMeta.setBaseColor(itemMeta.getBaseColor());
blockMeta.update(true, false);
}
}
BannerUtils.java 文件源码
项目:QuarSK
阅读 25
收藏 0
点赞 0
评论 0
public static String toMncPattern(@NotNull BannerMeta meta) {
List<String> stringList = new ArrayList<>();
stringList.add(colorToMnc(meta.getBaseColor()) + "a");
for (Pattern pattern : meta.getPatterns()) {
stringList.add(new String(new char[]{colorToMnc(pattern.getColor()), patternTypeToMnc(pattern.getPattern())}));
}
return StringUtils.join(stringList.toArray(new String[stringList.size()]));
}
ItemUtil.java 文件源码
项目:PA
阅读 27
收藏 0
点赞 0
评论 0
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;
}
FlagItem.java 文件源码
项目:Arcade2
阅读 25
收藏 0
点赞 0
评论 0
@Override
public boolean setItemMeta(ItemMeta meta) {
if (meta instanceof BannerMeta) {
return super.setItemMeta(meta);
}
throw new IllegalArgumentException("Flag's item meta must be an instance of the " +
BannerMeta.class.getSimpleName() + " class.");
}
BannerUtils.java 文件源码
项目:Arcade2
阅读 28
收藏 0
点赞 0
评论 0
public static BannerMeta meta(ItemStack item) {
if (isBanner(item)) {
return (BannerMeta) item.getItemMeta();
}
return null;
}
BannerUtils.java 文件源码
项目:Arcade2
阅读 25
收藏 0
点赞 0
评论 0
public static ItemStack toItem(ItemStack item, Banner block) {
BannerMeta meta = meta(item);
if (meta != null) {
item.setItemMeta(toMeta(meta, block));
}
return item;
}
IOUtil.java 文件源码
项目:BannerMaker
阅读 24
收藏 0
点赞 0
评论 0
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;
}
BannerUtil.java 文件源码
项目:BannerMaker
阅读 19
收藏 0
点赞 0
评论 0
/**
* 是否可以在生存模式合成(不超過6個pattern)
*
* @param banner 旗幟
* @return 是否可以合成
*/
static public boolean isCraftableInSurvival(ItemStack banner) {
//只檢查旗幟
if (!isBanner(banner)) {
return false;
}
int patternCount = ((BannerMeta) banner.getItemMeta()).numberOfPatterns();
return patternCount <= 6;
}
ItemMatcher.java 文件源码
项目:SupaCommons
阅读 28
收藏 0
点赞 0
评论 0
@Override
public boolean apply(@Nullable ItemStack item1, @Nullable ItemStack item2) {
Boolean b = precondition(item1, item2, true);
if (b != null) {
return b;
}
if (item1.getItemMeta() instanceof BannerMeta
&& item2.getItemMeta() instanceof BannerMeta) {
return ((BannerMeta) item1.getItemMeta()).getBaseColor()
.equals(((BannerMeta) item2.getItemMeta()).getBaseColor());
}
return false;
}
ItemMatcher.java 文件源码
项目:SupaCommons
阅读 23
收藏 0
点赞 0
评论 0
@Override
public boolean apply(@Nullable ItemStack item1, @Nullable ItemStack item2) {
Boolean b = precondition(item1, item2, true);
if (b != null) {
return b;
}
if (item1.getItemMeta() instanceof BannerMeta
&& item2.getItemMeta() instanceof BannerMeta) {
return ((BannerMeta) item1.getItemMeta()).getPatterns()
.equals(((BannerMeta) item2.getItemMeta()).getPatterns());
}
return false;
}
ItemBuilder.java 文件源码
项目:SupaCommons
阅读 25
收藏 0
点赞 0
评论 0
/**
* Sets this banner's base color, assuming it is a banner.
* <p />
* <b>UNSAFE</b>
*
* @param color base color to set
*
* @return this item builder instance, for chaining
*/
public ItemBuilder bannerColor(DyeColor color) {
if (isBannerMeta()) {
try {
((BannerMeta) this.itemMeta).setBaseColor(color);
} catch (Exception e) {
if (!this.failSilently) {
e.printStackTrace();
}
}
}
return this;
}