Java Code Examples for org.bukkit.Material#SPLASH_POTION

The following examples show how to use org.bukkit.Material#SPLASH_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: BrewingStandContainer.java    From Transport-Pipes with MIT License 6 votes vote down vote up
@Override
public int spaceForItem(TPDirection insertDirection, ItemStack insertion) {
    if (isInvLocked(cachedBrewingStand)) {
        return 0;
    }
    if (insertion.getType() == Material.POTION || insertion.getType() == Material.SPLASH_POTION || insertion.getType() == Material.LINGERING_POTION) {
        if (cachedInv.getItem(0) != null && cachedInv.getItem(1) != null && cachedInv.getItem(2) != null) {
            return 0;
        } else {
            return 1;
        }
    } else if (insertDirection.isSide() && insertion.getType() == Material.BLAZE_POWDER) {
        return spaceForItem(cachedInv.getFuel(), insertion);
    } else if (isBrewingIngredient(insertion.getType())) {
        return spaceForItem(cachedInv.getIngredient(), insertion);
    } else {
        return 0;
    }
}
 
Example 2
Source File: AutoDrier.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private ItemStack getOutput(ItemStack item) {
    for (int i = 0; i < recipeList.size(); i += 2) {
        if (SlimefunUtils.isItemSimilar(item, recipeList.get(i), true)) {
            return recipeList.get(i + 1);
        }
    }

    if (Tag.SAPLINGS.isTagged(item.getType())) {
        return new ItemStack(Material.STICK, 2);
    }
    else if (Tag.LEAVES.isTagged(item.getType())) {
        return new ItemStack(Material.STICK, 1);
    }
    else if (item.getType() == Material.SPLASH_POTION || item.getType() == Material.LINGERING_POTION) {
        return new ItemStack(Material.GLASS_BOTTLE);
    }

    return null;
}
 
Example 3
Source File: Potion.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts this potion to an {@link ItemStack} with the specified amount
 * and a correct damage value.
 *
 * @param amount The amount of the ItemStack
 * @return The created ItemStack
 */
public ItemStack toItemStack(int amount) {
    Material material;
    if (isSplash()) {
        material = Material.SPLASH_POTION;
    } else {
        material = Material.POTION;
    }
    ItemStack itemStack = new ItemStack(material, amount);
    PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
    meta.setBasePotionData(new PotionData(type, level == 2, extended));
    itemStack.setItemMeta(meta);
    return itemStack;
}
 
Example 4
Source File: BrewingStandContainer.java    From Transport-Pipes with MIT License 5 votes vote down vote up
@Override
public ItemStack insertItem(TPDirection insertDirection, ItemStack insertion) {
    if (!isInLoadedChunk()) {
        return insertion;
    }
    if (isInvLocked(cachedBrewingStand)) {
        return insertion;
    }
    if (insertion.getType() == Material.POTION || insertion.getType() == Material.SPLASH_POTION || insertion.getType() == Material.LINGERING_POTION) {
        if (cachedInv.getItem(0) == null) {
            cachedInv.setItem(0, insertion);
            return null;
        } else if (cachedInv.getItem(1) == null) {
            cachedInv.setItem(1, insertion);
            return null;
        } else if (cachedInv.getItem(2) == null) {
            cachedInv.setItem(2, insertion);
            return null;
        }
    } else if (insertDirection.isSide() && insertion.getType() == Material.BLAZE_POWDER) {
        ItemStack oldFuel = cachedInv.getFuel();
        cachedInv.setFuel(accumulateItems(oldFuel, insertion));
        if (insertion == null || insertion.getAmount() == 0) {
            insertion = null;
        }
    } else if (isBrewingIngredient(insertion.getType())) {
        ItemStack oldIngredient = cachedInv.getIngredient();
        cachedInv.setIngredient(accumulateItems(oldIngredient, insertion));
        if (insertion == null || insertion.getAmount() == 0) {
            insertion = null;
        }
    }
    return insertion;
}
 
Example 5
Source File: AutoPotion.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInteract(final PlayerInteractEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    // Not bypassed
    if (User.isUserInvalid(user, this.getModuleType())) {
        return;
    }

    // Timeout
    if (user.getTimestampMap().recentlyUpdated(TimestampKey.AUTOPOTION_TIMEOUT, timeout)) {
        event.setCancelled(true);
        return;
    }

    // Is the action a right-click that can throw a potion
    if ((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) &&
        // The item is a throwable potion
        event.getItem() != null &&
        event.getMaterial() == Material.SPLASH_POTION &&
        // The last sudden movement was not long ago
        user.getTimestampMap().recentlyUpdated(TimestampKey.AUTOPOTION_DETECTION, timeOffset))
    {
        user.getDataMap().setValue(DataKey.AUTOPOTION_ALREADY_THROWN, true);
        // Here the timestamp is used to contain the data of the last splash
        user.getTimestampMap().updateTimeStamp(TimestampKey.AUTOPOTION_DETECTION);
    }
}
 
Example 6
Source File: PotionVariable.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setItem(ItemStack item) {
	if (item != null) {
		Material type = item.getType();
		if (type != Material.SPLASH_POTION && type != Material.LINGERING_POTION) {
			item.setType(Material.SPLASH_POTION);
		}
	}
	super.setItem(item);
}
 
Example 7
Source File: PotionVariable.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isValidItem(Player player, ItemStack item) {
	Material type = item.getType();
	if (type != Material.POTION && type != Material.SPLASH_POTION && type != Material.LINGERING_POTION) {
		player.sendMessage("§cThat must be a must be a potion!");
		return false;
	}
	return true;
}
 
Example 8
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 9
Source File: AutoBrewer.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private ItemStack brew(Material input, Material potionType, PotionMeta potion) {
    PotionData data = potion.getBasePotionData();

    if (data.getType() == PotionType.WATER) {
        if (input == Material.FERMENTED_SPIDER_EYE) {
            potion.setBasePotionData(new PotionData(PotionType.WEAKNESS, false, false));
            return new ItemStack(potionType);
        }
        else if (input == Material.NETHER_WART) {
            potion.setBasePotionData(new PotionData(PotionType.AWKWARD, false, false));
            return new ItemStack(potionType);
        }
        else if (potionType == Material.POTION && input == Material.GUNPOWDER) {
            return new ItemStack(Material.SPLASH_POTION);
        }
        else if (potionType == Material.SPLASH_POTION && input == Material.DRAGON_BREATH) {
            return new ItemStack(Material.LINGERING_POTION);
        }
        else {
            return null;
        }

    }
    else if (input == Material.FERMENTED_SPIDER_EYE) {
        potion.setBasePotionData(new PotionData(fermentations.get(data.getType()), false, false));
        return new ItemStack(potionType);
    }
    else if (input == Material.REDSTONE) {
        potion.setBasePotionData(new PotionData(data.getType(), true, data.isUpgraded()));
        return new ItemStack(potionType);
    }
    else if (input == Material.GLOWSTONE_DUST) {
        potion.setBasePotionData(new PotionData(data.getType(), data.isExtended(), true));
        return new ItemStack(potionType);
    }
    else if (data.getType() == PotionType.AWKWARD && potionRecipes.containsKey(input)) {
        potion.setBasePotionData(new PotionData(potionRecipes.get(input), false, false));
        return new ItemStack(potionType);
    }
    else {
        return null;
    }
}
 
Example 10
Source File: CargoUtils.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
static ItemStack insertIntoVanillaInventory(ItemStack stack, Inventory inv) {
    ItemStack[] contents = inv.getContents();
    int minSlot = 0;
    int maxSlot = contents.length;

    // Check if it is a normal furnace
    if (inv instanceof FurnaceInventory) {
        // Check if it is fuel or not
        if (stack.getType().isFuel()) {
            maxSlot = 2;

            // Any non-smeltable items should not land in the upper slot
            if (!isSmeltable(stack, true)) {
                minSlot = 1;
            }
        }
        else {
            maxSlot = 1;
        }
    }
    else if (inv instanceof BrewerInventory) {
        if (stack.getType() == Material.POTION || stack.getType() == Material.LINGERING_POTION || stack.getType() == Material.SPLASH_POTION) {
            // Potions slot
            maxSlot = 3;
        }
        else if (stack.getType() == Material.BLAZE_POWDER) {
            // Blaze Powder slot
            minSlot = 4;
            maxSlot = 5;
        }
        else {
            // Input slot
            minSlot = 3;
            maxSlot = 4;
        }
    }

    ItemStackWrapper wrapper = new ItemStackWrapper(stack);

    for (int slot = minSlot; slot < maxSlot; slot++) {
        // Changes to this ItemStack are synchronized with the Item in the Inventory
        ItemStack itemInSlot = contents[slot];

        if (itemInSlot == null) {
            inv.setItem(slot, stack);
            return null;
        }
        else {
            int maxStackSize = itemInSlot.getType().getMaxStackSize();

            if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false) && itemInSlot.getAmount() < maxStackSize) {
                int amount = itemInSlot.getAmount() + stack.getAmount();

                if (amount > maxStackSize) {
                    stack.setAmount(amount - maxStackSize);
                }
                else {
                    stack = null;
                }

                itemInSlot.setAmount(Math.min(amount, maxStackSize));
                // Setting item in inventory will clone the ItemStack
                inv.setItem(slot, itemInSlot);

                return stack;
            }
        }
    }

    return stack;
}
 
Example 11
Source File: AutoBrewer.java    From Slimefun4 with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Checks whether a given {@link Material} is a valid Potion material.
 * 
 * @param mat
 *            The {@link Material} to check
 * 
 * @return Whether this {@link Material} is a valid potion
 */
private boolean isPotion(Material mat) {
    return mat == Material.POTION || mat == Material.SPLASH_POTION || mat == Material.LINGERING_POTION;
}