下面列出了org.bukkit.inventory.meta.PotionMeta#addCustomEffect ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void giveTeamReward(Player player){
Wolf wolf = (Wolf) player.getWorld().spawnEntity(player.getLocation(), EntityType.WOLF);
wolf.setTamed(true);
wolf.setOwner(player);
wolf.setAdult();
ItemStack potion = new ItemStack(Material.POTION);
PotionMeta meta = (PotionMeta) potion.getItemMeta();
meta.setMainEffect(PotionEffectType.SPEED);
PotionEffect potionEffect = new PotionEffect(PotionEffectType.SPEED, 8*60*20, 0);
meta.addCustomEffect(potionEffect, true);
meta.setDisplayName(ChatColor.WHITE + "Potion of Swiftness");
potion.setItemMeta(meta);
player.getWorld().dropItem(player.getLocation(), potion);
}
private static ItemMeta parseCustomPotionEffects(ItemMeta meta, JsonArray jsonArray) throws ParseException{
if (meta instanceof PotionMeta){
PotionMeta potionMeta = (PotionMeta) meta;
for (JsonElement jsonElement : jsonArray){
JsonObject effect = jsonElement.getAsJsonObject();
potionMeta.addCustomEffect(parsePotionEffect(effect), true);
}
return potionMeta;
}else{
return VersionUtils.getVersionUtils().applySuspiciousStewEffects(meta, jsonArray);
}
}
@Deprecated
public CustomPotion(String name, int durability, String[] lore, PotionEffect effect) {
super(Material.POTION, name, (ReflectionUtils.getVersion().startsWith("v1_8_")) ? durability: 0, lore);
PotionMeta meta = (PotionMeta) getItemMeta();
if (ReflectionUtils.getVersion().startsWith("v1_8_")) meta.setMainEffect(PotionEffectType.SATURATION);
else meta.setMainEffect(effect.getType());
meta.addCustomEffect(effect, true);
setItemMeta(meta);
}
public CustomPotion(String name, PotionType type, PotionEffect effect, String... lore) {
super(Material.POTION, name, lore);
PotionMeta meta = (PotionMeta) getItemMeta();
meta.setBasePotionData(new PotionData(type));
meta.addCustomEffect(effect, true);
setItemMeta(meta);
}
public CustomPotion(String name, Color color, PotionEffect effect, String... lore) {
super(Material.POTION, name, lore);
PotionMeta meta = (PotionMeta) getItemMeta();
meta.setColor(color);
meta.addCustomEffect(effect, true);
setItemMeta(meta);
}
@SuppressWarnings("unchecked")
private void parsePotionEffects() {
PotionMeta customPotionMeta = (PotionMeta) this.finalStack.getItemMeta();
for (Object potionEffect : (List<Object>) this.linkedSection.get("effects")) {
LinkedHashMap<String, Object> potionEffectSection =
(LinkedHashMap<String, Object>) potionEffect;
if (!potionEffectSection.containsKey("type")) {
continue;
}
PotionEffectType potionEffectType = null;
int duration = 1;
int amplifier = 0;
potionEffectType =
PotionEffectType.getByName(potionEffectSection.get("type").toString().toUpperCase());
if (potionEffectSection.containsKey("duration")) {
duration = Integer.parseInt(potionEffectSection.get("duration").toString()) * 20;
}
if (potionEffectSection.containsKey("amplifier")) {
amplifier = Integer.parseInt(potionEffectSection.get("amplifier").toString()) - 1;
}
if (potionEffectType == null) {
continue;
}
customPotionMeta.addCustomEffect(new PotionEffect(potionEffectType, duration, amplifier),
true);
}
this.finalStack.setItemMeta(customPotionMeta);
}