org.bukkit.potion.Potion Java Examples

The following examples show how to use org.bukkit.potion.Potion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InteractItemEvent.java    From Hawk with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void postProcess() {
    Material mat = getItemStack().getType();
    boolean gapple = mat == Material.GOLDEN_APPLE;
    if(action == Action.START_USE_ITEM) {
        if((mat.isEdible() && (p.getFoodLevel() < 20 || gapple) && p.getGameMode() != GameMode.CREATIVE) ||
                (mat == Material.POTION && getItemStack().getDurability() == 0) || //water bottles
                (mat == Material.POTION && !Potion.fromItemStack(getItemStack()).isSplash())) {
            pp.setConsumingItem(true);
        }
        if(EnchantmentTarget.WEAPON.includes(mat)) {
            pp.setBlocking(true);
        }
        if(mat == Material.BOW && (p.getInventory().contains(Material.ARROW) || p.getGameMode() == GameMode.CREATIVE)) {
            pp.setPullingBow(true);
        }
    }
    else if(action == Action.RELEASE_USE_ITEM || action == Action.DROP_HELD_ITEM || action == Action.DROP_HELD_ITEM_STACK) {
        pp.setConsumingItem(false);
        pp.setBlocking(false);
        pp.setPullingBow(false);
    }
}
 
Example #2
Source File: IndicatorListener.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@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"));
        }
    }
}
 
Example #3
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
	Player player = event.getPlayer();
	
	ItemMeta itemMeta = event.getItem().getItemMeta();
	if (itemMeta instanceof PotionMeta)
	{
		this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
	}
	else
	{
		Material material = event.getItem().getType();
		if (material == Material.MILK_BUCKET)
		{
			this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkMilk(player);
		}
	}
}
 
Example #4
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public boolean denyPotion(ItemStack result, Player p) {
    List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_potions;
    if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) {
        String potname = "";
        if (RedProtect.get().bukkitVersion >= 190) {
            PotionMeta pot = (PotionMeta) result.getItemMeta();
            potname = pot.getBasePotionData().getType().name();
        }
        if (RedProtect.get().bukkitVersion <= 180 && Potion.fromItemStack(result) != null) {
            potname = Potion.fromItemStack(result).getType().name();
        }
        if (Pots.contains(potname)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.denypotion");
            return true;
        }
    }
    return false;
}
 
Example #5
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public boolean denyPotion(ItemStack result, World world) {
    List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(world.getName()).deny_potions;
    if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) {
        String potname = "";
        if (RedProtect.get().bukkitVersion >= 190) {
            PotionMeta pot = (PotionMeta) result.getItemMeta();
            potname = pot.getBasePotionData().getType().name();
        }
        if (RedProtect.get().bukkitVersion < 190) {
            potname = Potion.fromItemStack(result).getType().name();
        }
        return Pots.contains(potname);
    }
    return false;
}
 
Example #6
Source File: ItemUtils.java    From ShopChest with MIT License 5 votes vote down vote up
public static boolean isExtendedPotion(ItemStack itemStack) {
    if (itemStack.getItemMeta() instanceof PotionMeta) {
        if (Utils.getMajorVersion() < 9) {
            return Potion.fromItemStack(itemStack).hasExtendedDuration();
        } else {
            return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().isExtended();
        }
    }

    return false;
}
 
Example #7
Source File: ItemUtils.java    From ShopChest with MIT License 5 votes vote down vote up
public static PotionType getPotionEffect(ItemStack itemStack) {
    if (itemStack.getItemMeta() instanceof PotionMeta) {    
        if (Utils.getMajorVersion() < 9) {
            return Potion.fromItemStack(itemStack).getType();
        } else {
            return ((PotionMeta) itemStack.getItemMeta()).getBasePotionData().getType();
        }
    }

    return null;
}
 
Example #8
Source File: SplashPotionsModule.java    From UHC with MIT License 5 votes vote down vote up
public SplashPotionsModule(PotionFuelsListener listener) {
    setId("SplashPotions");

    this.listener = listener;

    final Potion potion = new Potion(PotionType.POISON);
    potion.setSplash(true);

    this.icon.setType(Material.POTION);
    this.icon.setDurability(potion.toDamageValue());
    this.icon.setWeight(ModuleRegistry.CATEGORY_POTIONS);
    this.iconName = ICON_NAME;
}
 
Example #9
Source File: Tier2PotionsModule.java    From UHC with MIT License 5 votes vote down vote up
public Tier2PotionsModule(PotionFuelsListener listener) {
    setId("Tier2Potions");

    this.listener = listener;

    final Potion potion = new Potion(PotionType.INSTANT_HEAL);
    potion.setLevel(2);

    this.icon.setType(Material.POTION);
    this.icon.setDurability(potion.toDamageValue());
    this.icon.setWeight(ModuleRegistry.CATEGORY_POTIONS);
    this.iconName = ICON_NAME;
}
 
Example #10
Source File: InventoryUtils.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Collection<PotionEffect> getEffects(ItemStack potion) {
  if (potion.getItemMeta() instanceof PotionMeta) {
    PotionMeta meta = (PotionMeta) potion.getItemMeta();
    if (meta.hasCustomEffects()) {
      return meta.getCustomEffects();
    } else {
      return Potion.fromItemStack(potion).getEffects();
    }
  } else {
    return Collections.emptyList();
  }
}
 
Example #11
Source File: CraftThrownPotion.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public Collection<PotionEffect> getEffects() {
    return Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionDamage());
}
 
Example #12
Source File: CraftEffect.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public static <T> int getDataValue(Effect effect, T data) {
    int datavalue;
    switch(effect) {
    case POTION_BREAK:
        datavalue = ((Potion) data).toDamageValue() & 0x3F;
        break;
    case RECORD_PLAY:
        Validate.isTrue(((Material) data).isRecord(), "Invalid record type!");
        datavalue = ((Material) data).getId();
        break;
    case SMOKE:
        switch((BlockFace) data) { // TODO: Verify (Where did these values come from...?)
        case SOUTH_EAST:
            datavalue = 0;
            break;
        case SOUTH:
            datavalue = 1;
            break;
        case SOUTH_WEST:
            datavalue = 2;
            break;
        case EAST:
            datavalue = 3;
            break;
        case UP:
        case SELF:
            datavalue = 4;
            break;
        case WEST:
            datavalue = 5;
            break;
        case NORTH_EAST:
            datavalue = 6;
            break;
        case NORTH:
            datavalue = 7;
            break;
        case NORTH_WEST:
            datavalue = 8;
            break;
        default:
            throw new IllegalArgumentException("Bad smoke direction!");
        }
        break;
    case STEP_SOUND:
        Validate.isTrue(((Material) data).isBlock(), "Material is not a block!");
        datavalue = ((Material) data).getId();
        break;
    default:
        datavalue = 0;
    }
    return datavalue;
}
 
Example #13
Source File: UMaterial.java    From TradePlus with GNU General Public License v3.0 4 votes vote down vote up
public static UMaterial matchPotion(ItemStack potion) {
  if(potion != null && potion.getItemMeta() instanceof PotionMeta) {
    final PotionMeta p = (PotionMeta) potion.getItemMeta();
    final List<PotionEffect> ce = p.getCustomEffects();
    if(ce.size() == 0) {
      final String base;
      final PotionEffectType t;
      final int l, max;
      final boolean extended;
      if(EIGHT) {
        final Potion po = Potion.fromItemStack(potion);
        base = po.isSplash() ? "SPLASH_POTION_" : "POTION_";
        final Collection<PotionEffect> e = po.getEffects();
        t = e.size() > 0 ? ((PotionEffect) e.toArray()[0]).getType() : null;
        l = po.getLevel();
        final PotionType ty = po.getType();
        max = ty != null ? ty.getMaxLevel() : 0;
        extended = po.hasExtendedDuration();
      } else {
        final org.bukkit.potion.PotionData pd = p.getBasePotionData();
        final PotionType type = pd.getType();
        base = potion.getType().name() + "_";
        t = type.getEffectType();
        l = type.isUpgradeable() && pd.isUpgraded() ? 2 : 1;
        max = type.getMaxLevel();
        extended = type.isExtendable() && pd.isExtended();
      }
      final String a = t != null ? t.getName() : null,
          type = a != null ? a.equals("SPEED") ? "SWIFTNESS"
                                 : a.equals("SLOW") ? "SLOWNESS"
                                       : a.equals("INCREASE_DAMAGE") ? "STRENGTH"
                                             : a.equals("HEAL") ? "HEALING"
                                                   : a.equals("HARM") ? "HARMING"
                                                         : a.equals("JUMP") ? "LEAPING"
                                                               : a : null;
      if(type != null) {
        final String g = base + type + (max != 1 && l <= max ? "_" + l : "") + (extended ? "_EXTENDED" : "");
        return valueOf(g);
      } else {
        return UMaterial.POTION;
      }
    }
  }
  return null;
}
 
Example #14
Source File: Loadout.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
public Loadout addHealthPotion1()
{
	return addItem(KitUtils.addSoulbound((new Potion(PotionType.INSTANT_HEAL, 1, false,false).toItemStack(1))));
}
 
Example #15
Source File: Vampire.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@Override
protected Loadout getFinalLoadout()
{
	return new Loadout().addStoneSword().addWoodPick().addWoodAxe()
			.addItem(new Potion(PotionType.NIGHT_VISION).toItemStack(1));
}
 
Example #16
Source File: PotionUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Collection<PotionEffect> effects(PotionData data) {
    return Potion.getBrewer().getEffects(data.getType(), data.isUpgraded(), data.isExtended());
}
 
Example #17
Source File: GlobalItemParser.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public ItemStack parseItem(Element el, Material type, short damage) throws InvalidXMLException {
    int amount = XMLUtils.parseNumber(el.getAttribute("amount"), Integer.class, 1);

    // If the item is a potion with non-zero damage, and there is
    // no modern potion ID, decode the legacy damage value.
    final Potion legacyPotion;
    if(type == Material.POTION && damage > 0 && el.getAttribute("potion") == null) {
        try {
            legacyPotion = Potion.fromDamage(damage);
        } catch(IllegalArgumentException e) {
            throw new InvalidXMLException("Invalid legacy potion damage value " + damage + ": " + e.getMessage(), el, e);
        }

        // If the legacy splash bit is set, convert to a splash potion
        if(legacyPotion.isSplash()) {
            type = Material.SPLASH_POTION;
            legacyPotion.setSplash(false);
        }

        // Potions always have damage 0
        damage = 0;
    } else {
        legacyPotion = null;
    }

    ItemStack itemStack = new ItemStack(type, amount, damage);
    if(itemStack.getType() != type) {
        throw new InvalidXMLException("Invalid item/block", el);
    }

    final ItemMeta meta = itemStack.getItemMeta();
    if(meta != null) { // This happens if the item is "air"
        parseItemMeta(el, meta);

        // If we decoded a legacy potion, apply it now, but only if there are no custom effects.
        // This emulates the old behavior of custom effects overriding default effects.
        if(legacyPotion != null) {
            final PotionMeta potionMeta = (PotionMeta) meta;
            if(!potionMeta.hasCustomEffects()) {
                potionMeta.setBasePotionData(new PotionData(legacyPotion.getType(),
                                                            legacyPotion.hasExtendedDuration(),
                                                            legacyPotion.getLevel() == 2));
            }
        }

        itemStack.setItemMeta(meta);
    }

    return itemStack;
}
 
Example #18
Source File: CraftEffect.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public static <T> int getDataValue(Effect effect, T data) {
    int datavalue;
    switch (effect) {
        case VILLAGER_PLANT_GROW:
            datavalue = (Integer) data;
            break;
        case POTION_BREAK:
            datavalue = ((Potion) data).toDamageValue() & 0x3F;
            break;
        case RECORD_PLAY:
            Validate.isTrue(((Material) data).isRecord(), "Invalid record type!");
            datavalue = ((Material) data).getId();
            break;
        case SMOKE:
            switch ((BlockFace) data) { // TODO: Verify (Where did these values come from...?)
                case SOUTH_EAST:
                    datavalue = 0;
                    break;
                case SOUTH:
                    datavalue = 1;
                    break;
                case SOUTH_WEST:
                    datavalue = 2;
                    break;
                case EAST:
                    datavalue = 3;
                    break;
                case UP:
                case SELF:
                    datavalue = 4;
                    break;
                case WEST:
                    datavalue = 5;
                    break;
                case NORTH_EAST:
                    datavalue = 6;
                    break;
                case NORTH:
                    datavalue = 7;
                    break;
                case NORTH_WEST:
                    datavalue = 8;
                    break;
                default:
                    throw new IllegalArgumentException("Bad smoke direction!");
            }
            break;
        case STEP_SOUND:
            Validate.isTrue(((Material) data).isBlock(), "Material is not a block!");
            datavalue = ((Material) data).getId();
            break;
        case ITEM_BREAK:
            datavalue = ((Material) data).getId();
            break;
        default:
            datavalue = 0;
    }
    return datavalue;
}
 
Example #19
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #20
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #21
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #22
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #23
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
    StringTag stringTag = ((StringTag)contents.get("Potion"));
    if (stringTag != null) {
        String tag = stringTag.getValue().replace("minecraft:", "");
        PotionType type = null;
        boolean strong = tag.contains("strong");
        boolean _long = tag.contains("long");
        //Bukkit.getLogger().info("tag = " + tag);
        if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
            type = PotionType.FIRE_RESISTANCE;
        }else if(tag.equals("harming") || tag.equals("strong_harming")){
            type = PotionType.INSTANT_DAMAGE;
        }else if(tag.equals("healing") || tag.equals("strong_healing")){
            type = PotionType.INSTANT_HEAL;
        }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
            type = PotionType.INVISIBILITY;
        }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
            type = PotionType.JUMP;
        }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
            type = PotionType.NIGHT_VISION;
        }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
            type = PotionType.POISON;
        }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
            type = PotionType.REGEN;
        }else if(tag.equals("slowness") || tag.equals("long_slowness")){
            type = PotionType.SLOWNESS;
        }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
            type = PotionType.SPEED;
        }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
            type = PotionType.STRENGTH;
        }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
            type = PotionType.WATER_BREATHING;
        }else if(tag.equals("water")){
            type = PotionType.WATER;
        }else if(tag.equals("weakness") || tag.equals("long_weakness")){
            type = PotionType.WEAKNESS;
        }else{
            return chestItem;
        }
        Potion potion = new Potion(type);
        potion.setHasExtendedDuration(_long);
        potion.setLevel(strong ? 2 : 1);
        chestItem = potion.toItemStack(chestItem.getAmount());
    }

    return chestItem;
}
 
Example #24
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags,
        ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String,Tag> cont = (Map<String,Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String,Tag> contents = (Map<String,Tag>)((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag)contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                //Bukkit.getLogger().info("tag = " + tag);
                if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){
                    type = PotionType.FIRE_RESISTANCE;
                }else if(tag.equals("harming") || tag.equals("strong_harming")){
                    type = PotionType.INSTANT_DAMAGE;
                }else if(tag.equals("healing") || tag.equals("strong_healing")){
                    type = PotionType.INSTANT_HEAL;
                }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){
                    type = PotionType.INVISIBILITY;
                }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){
                    type = PotionType.JUMP;
                }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){
                    type = PotionType.NIGHT_VISION;
                }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){
                    type = PotionType.POISON;
                }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){
                    type = PotionType.REGEN;
                }else if(tag.equals("slowness") || tag.equals("long_slowness")){
                    type = PotionType.SLOWNESS;
                }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){
                    type = PotionType.SPEED;
                }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){
                    type = PotionType.STRENGTH;
                }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){
                    type = PotionType.WATER_BREATHING;
                }else if(tag.equals("water")){
                    type = PotionType.WATER;
                }else if(tag.equals("weakness") || tag.equals("long_weakness")){
                    type = PotionType.WEAKNESS;
                }else{
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }

    return chestItem;
}
 
Example #25
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftServer(MinecraftServer console, PlayerList playerList) {
    this.console = console;
    this.playerList = (DedicatedPlayerList) playerList;
    this.playerView = Collections.unmodifiableList(Lists.transform(playerList.getPlayers(), EntityPlayerMP::getBukkitEntity));
    this.serverVersion = CraftServer.class.getPackage().getImplementationVersion();
    online.value = console.getPropertyManager().getBooleanProperty("online-mode", true);

    Bukkit.setServer(this);

    // Register all the Enchantments and PotionTypes now so we can stop new registration immediately after
    Enchantments.SHARPNESS.getClass();

    Potion.setPotionBrewer(new CraftPotionBrewer());
    MobEffects.BLINDNESS.getClass();
    // Ugly hack :(

    if (!Main.useConsole) {
        getLogger().info("Console input is disabled due to --noconsole command argument");
    }

    configuration = YamlConfiguration.loadConfiguration(getConfigFile());
    configuration.options().copyDefaults(true);
    configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(
            getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml"), Charsets.UTF_8)));
    ConfigurationSection legacyAlias = null;
    if (!configuration.isString("aliases")) {
        legacyAlias = configuration.getConfigurationSection("aliases");
        configuration.set("aliases", "now-in-commands.yml");
    }
    saveConfig();
    if (getCommandsConfigFile().isFile()) {
        legacyAlias = null;
    }
    commandsConfiguration = YamlConfiguration.loadConfiguration(getCommandsConfigFile());
    commandsConfiguration.options().copyDefaults(true);
    commandsConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(
            getClass().getClassLoader().getResourceAsStream("configurations/commands.yml"), Charsets.UTF_8)));
    saveCommandsConfig();

    // Migrate aliases from old file and add previously implicit $1- to pass all arguments
    if (legacyAlias != null) {
        ConfigurationSection aliases = commandsConfiguration.createSection("aliases");
        for (String key : legacyAlias.getKeys(false)) {
            ArrayList<String> commands = new ArrayList<String>();

            if (legacyAlias.isList(key)) {
                for (String command : legacyAlias.getStringList(key)) {
                    commands.add(command + " $1-");
                }
            } else {
                commands.add(legacyAlias.getString(key) + " $1-");
            }

            aliases.set(key, commands);
        }
    }

    saveCommandsConfig();
    overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*");
    unrestrictedAdvancements = commandsConfiguration.getBoolean("unrestricted-advancements");
    pluginManager.useTimings(configuration.getBoolean("settings.plugin-profiling"));
    monsterSpawn = configuration.getInt("spawn-limits.monsters");
    animalSpawn = configuration.getInt("spawn-limits.animals");
    waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
    ambientSpawn = configuration.getInt("spawn-limits.ambient");
    console.autosavePeriod = configuration.getInt("ticks-per.autosave");
    warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
    loadIcon(); // Fixed server ping stalling.
    chunkGCPeriod = configuration.getInt("chunk-gc.period-in-ticks");
    chunkGCLoadThresh = configuration.getInt("chunk-gc.load-threshold");
    loadIcon();
}