本文整理匯總了Java中org.bukkit.potion.Potion.fromItemStack方法的典型用法代碼示例。如果您正苦於以下問題:Java Potion.fromItemStack方法的具體用法?Java Potion.fromItemStack怎麽用?Java Potion.fromItemStack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.potion.Potion
的用法示例。
在下文中一共展示了Potion.fromItemStack方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setMainPotionEffect
import org.bukkit.potion.Potion; //導入方法依賴的package包/類
public ItemBuilder setMainPotionEffect(PotionType type, boolean extendedDurability, int level, boolean splash) {
if (! (meta instanceof PotionMeta))
return this;
Potion potion = Potion.fromItemStack(stack);
potion.setType(type);
if (! type.isInstant())
potion.setHasExtendedDuration(extendedDurability);
potion.setLevel(level);
potion.setSplash(splash);
potion.apply(stack);
return this;
}
示例2: denyPotion
import org.bukkit.potion.Potion; //導入方法依賴的package包/類
public static boolean denyPotion(ItemStack result, Player p){
List<String> Pots = RPConfig.getStringList("server-protection.deny-potions");
if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))){
String potname = "";
if (RedProtect.get().version >= 190){
PotionMeta pot = (PotionMeta) result.getItemMeta();
potname = pot.getBasePotionData().getType().name();
}
if (RedProtect.get().version <= 180 && Potion.fromItemStack(result) != null){
potname = Potion.fromItemStack(result).getType().name();
}
if (Pots.contains(potname)){
RPLang.sendMessage(p, "playerlistener.denypotion");
return true;
}
}
return false;
}
示例3: onConsumePotion
import org.bukkit.potion.Potion; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onConsumePotion(PlayerItemConsumeEvent event) {
if (Settings.INDICATOR_ENABLE.getValue("potion")) {
if (event.getItem().getType() == Material.POTION) {
Potion potion = Potion.fromItemStack(event.getItem());
if (potion != null) {
this.showPotionHologram(event.getPlayer(), potion.getEffects());
}
} else if (event.getItem().getType() == Material.GOLDEN_APPLE) {
String msg = Settings.INDICATOR_FORMAT.getValue("potion", "goldenapple");
if (event.getItem().getDurability() == 1) {
msg = Settings.INDICATOR_FORMAT.getValue("potion", "godapple");
}
Location l = event.getPlayer().getLocation().clone();
l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion"));
HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, msg.replace("%effect%", "Golden Apple"));
}
}
}
示例4: onPlayerConsume
import org.bukkit.potion.Potion; //導入方法依賴的package包/類
/**
* Checks to see if the player is attempting to drink a potion, and checks
* the potion to see if it is allowed.
*
* @param event The PlayerItemConsumeEvent involving the player.
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
if (event.getItem().getType() != Material.POTION) {
return;
}
// Check the type of potion in the player's hand
Potion potion = Potion.fromItemStack(event.getItem());
Collection<PotionEffect> effects = potion.getEffects();
for (PotionEffect e : effects) {
if (!(Util.canUsePotion(event.getPlayer(), e.getType()))) {
// If we get here, we cancel this event and all is done.
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You cannot use that potion here!");
Util.removeDisallowedEffects(event.getPlayer());
return; // We don't need to check any more.
}
}
}
示例5: testValidity
import org.bukkit.potion.Potion; //導入方法依賴的package包/類
private boolean testValidity(ItemStack[] contents) {
for (ItemStack stack : contents) {
if (stack != null && stack.getType() == Material.POTION && stack.getDurability() != 0) {
Potion potion = Potion.fromItemStack(stack);
// Just to be safe, null check this.
if (potion == null)
continue;
PotionType type = potion.getType();
// Mundane potions etc, can return a null type
if (type == null)
continue;
// is 33s poison, allow
if (type == PotionType.POISON && !potion.hasExtendedDuration() && potion.getLevel() == 1) {
continue;
}
if (potion.getLevel() > getMaxLevel(type)) {
return false;
}
}
}
return true;
}
示例6: isExtendedPotion
import org.bukkit.potion.Potion; //導入方法依賴的package包/類
public static boolean isExtendedPotion(ItemStack itemStack) {
if (itemStack.getItemMeta() instanceof PotionMeta) {
if (Utils.getMajorVersion() >= 9) {
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
return potionMeta.getBasePotionData().isExtended();
} else {
Potion potion = Potion.fromItemStack(itemStack);
return potion.hasExtendedDuration();
}
}
return false;
}
示例7: use
import org.bukkit.potion.Potion; //導入方法依賴的package包/類
public boolean use(Fight fight, Character attacking, Character defending, ItemStack weapon) {
Player attackingPlayer = attacking.getPlayer().getPlayer();
Player defendingPlayer = defending.getPlayer().getPlayer();
if (weapon.getType().isEdible() || weapon.getType() == Material.POTION) {
switch (weapon.getType()) {
case GOLDEN_APPLE:
attackingPlayer.getInventory().removeItem(weapon);
defending.setHealth(Math.min(defending.getHealth() + 10, defending.getMaxHealth()));
defendingPlayer.setHealth(defending.getHealth());
fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " fed " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + " a golden carrot, healing 5 HP.");
return true;
case POTION:
if (weapon.hasItemMeta()) {
if (weapon.getItemMeta().hasDisplayName()) {
if (weapon.getItemMeta().getDisplayName().equalsIgnoreCase("Masheek")) {
attackingPlayer.getInventory().removeItem(weapon);
defending.setMana(Math.min(defending.getMana() + 5, defending.getMaxMana()));
fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " used a bottle of Masheek on " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + ", replenishing 5 mana.");
return true;
}
}
}
attackingPlayer.getInventory().removeItem(weapon);
Potion potion = Potion.fromItemStack(weapon);
potion.apply(defendingPlayer);
fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " used a potion on " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()));
return true;
default:
fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " fed something to " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + " but it had no effect.");
return true;
}
} else {
fight.sendMessage(ChatColor.YELLOW + (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " attempted to use a " + weapon.getType().toString().toLowerCase().replace('_', ' ') + " on " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + " but it didn't seem to do anything.");
return true;
}
}
示例8: toPotion
import org.bukkit.potion.Potion; //導入方法依賴的package包/類
public Potion toPotion(int amount) {
return Potion.fromItemStack(this.toItemStack(amount));
}