本文整理汇总了Java中org.bukkit.block.banner.Pattern类的典型用法代码示例。如果您正苦于以下问题:Java Pattern类的具体用法?Java Pattern怎么用?Java Pattern使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pattern类属于org.bukkit.block.banner包,在下文中一共展示了Pattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BannerCustomItem
import org.bukkit.block.banner.Pattern; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public BannerCustomItem(Material material, Config config, PlaceholderRegistry placeholders) {
super(material, config, placeholders);
this.baseColor = config.getDye("baseColor");
Collection<Map<String, Object>> rawPatterns = (Collection<Map<String, Object>>) config.getCollection("patterns");
patterns = new ArrayList<>();
if(rawPatterns != null) {
for (Map<String, Object> p : rawPatterns) {
Config sub = Config.wrap(p);
DyeColor color = sub.getDyeRequired("color");
PatternType type = PatternType.getByIdentifier(sub.getStringRequired("pattern"));
if (type == null) {
Uppercore.logger().severe("Cannot find pattern identifier \"" + p.get("pattern") + "\"");
type = PatternType.BASE;
}
patterns.add(new Pattern(color, type));
}
}
}
示例2: change
import org.bukkit.block.banner.Pattern; //导入依赖的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.block.banner.Pattern; //导入依赖的package包/类
@Override
public void change(Event e, Object[] delta, @NotNull Changer.ChangeMode mode) {
Block b = block.getSingle(e);
if (b == null) {
return;
}
if (b.getType() == Material.BANNER) {
Banner banner = (Banner) b.getState();
Pattern[] patterns = (Pattern[]) delta;
switch (mode) {
case ADD:
Arrays.asList(patterns).forEach(banner::addPattern);
break;
case SET:
banner.setPatterns(Arrays.asList(patterns));
break;
case DELETE:
case RESET:
for (int i = 1; i <= banner.numberOfPatterns(); i++)
banner.removePattern(i);
break;
}
banner.update(true, false);
}
}
示例4: parseMncPattern
import org.bukkit.block.banner.Pattern; //导入依赖的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: setPattern
import org.bukkit.block.banner.Pattern; //导入依赖的package包/类
/**
* Set a {@link Pattern} on the banner item at the specified index.
* <p/>
* If the index is below 0 nothing will happen,
* if it's too high the pattern will be added on the end instead.
* <p/>
* Items: {@link Material#BANNER}
*
* @param index The index to set the pattern at.
* @param pattern Pattern to set on the banner.
* @return this instance.
*/
public EItem setPattern(Integer index, Pattern pattern) {
if (index < 0) {
return this;
}
ItemMeta meta = getItemMeta();
if (meta instanceof BannerMeta) {
if (((BannerMeta)meta).getPatterns().size() > index) {
((BannerMeta)meta).setPattern(index, pattern);
} else {
((BannerMeta)meta).addPattern(pattern);
}
setItemMeta(meta);
}
return this;
}
示例6: handleBanner
import org.bukkit.block.banner.Pattern; //导入依赖的package包/类
/** Handles banners; only base color (as patterns would be too much data) */
private void handleBanner(JsonWriter out, BannerMeta meta) throws IOException
{
DyeColor baseColor = meta.getBaseColor();
// Due to SPIGOT-746, we sometimes have to get the base color from pattern 0...
if (baseColor == null)
{
List<Pattern> patterns = meta.getPatterns();
if (patterns.size() <= 0)
return;
else
baseColor = patterns.get(0).getColor();
}
if (baseColor != null)
out.name("baseColor").value( baseColor.toString() );
out.name("patternCount").value( meta.numberOfPatterns() );
}
示例7: saveBanner
import org.bukkit.block.banner.Pattern; //导入依赖的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: bannerAdd
import org.bukkit.block.banner.Pattern; //导入依赖的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;
}
示例9: serializeBanner
import org.bukkit.block.banner.Pattern; //导入依赖的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;
}
}
示例10: getBannerMeta
import org.bukkit.block.banner.Pattern; //导入依赖的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;
}
}
示例11: update
import org.bukkit.block.banner.Pattern; //导入依赖的package包/类
@Override
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
banner.color = base.getDyeData();
NBTTagList newPatterns = new NBTTagList();
for (Pattern p : patterns) {
NBTTagCompound compound = new NBTTagCompound();
compound.setInt("Color", p.getColor().getDyeData());
compound.setString("Pattern", p.getPattern().getIdentifier());
newPatterns.add(compound);
}
banner.patterns = newPatterns;
banner.update();
}
return result;
}
示例12: CraftMetaBanner
import org.bukkit.block.banner.Pattern; //导入依赖的package包/类
CraftMetaBanner(NBTTagCompound tag) {
super(tag);
if (!tag.hasKey("BlockEntityTag")) {
return;
}
NBTTagCompound entityTag = tag.getCompound("BlockEntityTag");
base = entityTag.hasKey(BASE.NBT) ? DyeColor.getByDyeData((byte) entityTag.getInt(BASE.NBT)) : null;
if (entityTag.hasKey(PATTERNS.NBT)) {
NBTTagList patterns = entityTag.getList(PATTERNS.NBT, 10);
for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
NBTTagCompound p = patterns.get(i);
this.patterns.add(new Pattern(DyeColor.getByDyeData((byte) p.getInt(COLOR.NBT)), PatternType.getByIdentifier(p.getString(PATTERN.NBT))));
}
}
}
示例13: applyToItem
import org.bukkit.block.banner.Pattern; //导入依赖的package包/类
@Override
void applyToItem(NBTTagCompound tag) {
super.applyToItem(tag);
NBTTagCompound entityTag = new NBTTagCompound();
if (base != null) {
entityTag.setInt(BASE.NBT, base.getDyeData());
}
NBTTagList newPatterns = new NBTTagList();
for (Pattern p : patterns) {
NBTTagCompound compound = new NBTTagCompound();
compound.setInt(COLOR.NBT, p.getColor().getDyeData());
compound.setString(PATTERN.NBT, p.getPattern().getIdentifier());
newPatterns.add(compound);
}
entityTag.set(PATTERNS.NBT, newPatterns);
tag.set("BlockEntityTag", entityTag);
}
示例14: serializeBanner
import org.bukkit.block.banner.Pattern; //导入依赖的package包/类
private static Map<String, Object> serializeBanner(Banner banner) {
Map<String, Object> serializedBanner = new LinkedHashMap<>();
if (banner != null) {
DyeColor baseDyeColor = banner.getBaseColor();
if (baseDyeColor != null) {
serializedBanner.put("Base", Utilities.serializeColor(baseDyeColor.getColor()));
}
List<Pattern> bannerPatterns = banner.getPatterns();
if (bannerPatterns != null && !bannerPatterns.isEmpty()) {
Map<String, Map<String, Object>> serializedPatterns = new LinkedHashMap<>();
for (int patternIndex = 0; patternIndex < bannerPatterns.size(); patternIndex++) {
Pattern bannerPattern = bannerPatterns.get(patternIndex);
Map<String, Object> serializedPattern = new LinkedHashMap<>();
if (bannerPattern.getColor() != null) {
serializedPattern.put("Color", Utilities.serializeColor(bannerPattern.getColor().getColor()));
}
serializedPattern.put("Pattern", StringUtilities.capitalizeFully(bannerPattern.getPattern().name().replace('_', ' ')));
serializedPatterns.put("Pattern " + (patternIndex + 1), serializedPattern);
}
serializedBanner.put("Patterns", serializedPatterns);
}
}
return serializedBanner;
}
示例15: update
import org.bukkit.block.banner.Pattern; //导入依赖的package包/类
@Override
public boolean update(boolean force, boolean applyPhysics) {
boolean result = (isPlaced()) ? super.update(force, applyPhysics) : true;
if (result) {
banner.color = base.getDyeData();
NBTTagList newPatterns = new NBTTagList();
for (Pattern p : patterns) {
NBTTagCompound compound = new NBTTagCompound();
compound.setInt("Color", p.getColor().getDyeData());
compound.setString("Pattern", p.getPattern().getIdentifier());
newPatterns.add(compound);
}
banner.patterns = newPatterns;
banner.update();
}
return result;
}