use of org.bukkit.potion.PotionType in project Essentials by drtshock.
the class BasePotionDataProvider method createPotionItem.
@Override
public ItemStack createPotionItem(Material initial, int effectId) throws IllegalArgumentException {
ItemStack potion = new ItemStack(initial, 1);
if (effectId == 0) {
return potion;
}
int damageValue = getBit(effectId, 0) + 2 * getBit(effectId, 1) + 4 * getBit(effectId, 2) + 8 * getBit(effectId, 3);
PotionType type = damageValueToType.get(damageValue);
if (type == null) {
throw new IllegalArgumentException("Unable to process potion effect ID " + effectId + " with damage value " + damageValue);
}
boolean extended = getBit(effectId, 6) == 1;
boolean upgraded = getBit(effectId, 5) == 1;
boolean splash = getBit(effectId, 14) == 1;
if (splash && initial == Material.POTION) {
potion = new ItemStack(Material.SPLASH_POTION, 1);
}
PotionMeta meta = (PotionMeta) potion.getItemMeta();
PotionData data = new PotionData(type, extended, upgraded);
// this method is exclusive to recent 1.9+
meta.setBasePotionData(data);
potion.setItemMeta(meta);
return potion;
}
use of org.bukkit.potion.PotionType in project Glowstone by GlowstoneMC.
the class GlowMetaPotion method dataFromString.
/**
* Converts a Potion ID string to the PotionData of this item meta.
*
* @param string the Potion ID string
* @return the resultant PotionData
*/
private PotionData dataFromString(String string) {
PotionType type;
boolean extended = false, upgraded = false;
if (string.startsWith("minecraft:"))
string = string.replace("minecraft:", "");
if (string.startsWith("long_")) {
string = string.replace("long_", "");
extended = true;
} else if (string.startsWith("strong_")) {
string = string.replace("strong_", "");
upgraded = true;
}
type = PotionTypeTable.fromName(string);
return new PotionData(type, extended, upgraded);
}
use of org.bukkit.potion.PotionType in project acidisland by tastybento.
the class Challenges method giveItems.
/**
* Gives player the reward items.
* @param player
* @param itemRewards
* @return List of ItemStacks that were given to the player or null if there was an error in the interpretation of the rewards
*/
private List<ItemStack> giveItems(Player player, String[] itemRewards) {
List<ItemStack> rewardedItems = new ArrayList<ItemStack>();
Material rewardItem;
int rewardQty;
// Build the item stack of rewards to give the player
for (final String s : itemRewards) {
final String[] element = s.split(":");
if (element.length == 2) {
try {
if (StringUtils.isNumeric(element[0])) {
rewardItem = Material.getMaterial(Integer.parseInt(element[0]));
} else {
rewardItem = Material.getMaterial(element[0].toUpperCase());
}
rewardQty = Integer.parseInt(element[1]);
ItemStack item = new ItemStack(rewardItem, rewardQty);
rewardedItems.add(item);
final HashMap<Integer, ItemStack> leftOvers = player.getInventory().addItem(new ItemStack[] { item });
if (!leftOvers.isEmpty()) {
player.getWorld().dropItemNaturally(player.getLocation(), leftOvers.get(0));
}
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
player.getWorld().playSound(player.getLocation(), Sound.valueOf("ITEM_PICKUP"), 1F, 1F);
} else {
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1F, 1F);
}
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorRewardProblem);
plugin.getLogger().severe("Could not give " + element[0] + ":" + element[1] + " to " + player.getName() + " for challenge reward!");
String materialList = "";
boolean hint = false;
for (Material m : Material.values()) {
materialList += m.toString() + ",";
if (element[0].length() > 3) {
if (m.toString().startsWith(element[0].substring(0, 3))) {
plugin.getLogger().severe("Did you mean " + m.toString() + "? If so, put that in challenges.yml.");
hint = true;
}
}
}
if (!hint) {
plugin.getLogger().severe("Sorry, I have no idea what " + element[0] + " is. Pick from one of these:");
plugin.getLogger().severe(materialList.substring(0, materialList.length() - 1));
}
}
} else if (element.length == 3) {
try {
if (StringUtils.isNumeric(element[0])) {
rewardItem = Material.getMaterial(Integer.parseInt(element[0]));
} else {
rewardItem = Material.getMaterial(element[0].toUpperCase());
}
rewardQty = Integer.parseInt(element[2]);
// Check for POTION
if (rewardItem.equals(Material.POTION)) {
givePotion(player, rewardedItems, element, rewardQty);
} else {
ItemStack item = null;
// Normal item, not a potion, check if it is a Monster Egg
if (rewardItem.equals(Material.MONSTER_EGG)) {
try {
EntityType type = EntityType.valueOf(element[1].toUpperCase());
if (Bukkit.getServer().getVersion().contains("(MC: 1.8") || Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
item = new SpawnEgg(type).toItemStack(rewardQty);
} else {
try {
item = new SpawnEgg1_9(type).toItemStack(rewardQty);
} catch (Exception ex) {
item = new ItemStack(rewardItem);
plugin.getLogger().severe("Monster eggs not supported with this server version.");
}
}
} catch (Exception e) {
Bukkit.getLogger().severe("Spawn eggs must be described by name. Try one of these (not all are possible):");
for (EntityType type : EntityType.values()) {
if (type.isSpawnable() && type.isAlive()) {
plugin.getLogger().severe(type.toString());
}
}
}
} else {
int rewMod = Integer.parseInt(element[1]);
item = new ItemStack(rewardItem, rewardQty, (short) rewMod);
}
if (item != null) {
rewardedItems.add(item);
final HashMap<Integer, ItemStack> leftOvers = player.getInventory().addItem(new ItemStack[] { item });
if (!leftOvers.isEmpty()) {
player.getWorld().dropItemNaturally(player.getLocation(), leftOvers.get(0));
}
}
}
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
player.getWorld().playSound(player.getLocation(), Sound.valueOf("ITEM_PICKUP"), 1F, 1F);
} else {
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1F, 1F);
}
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + "There was a problem giving your reward. Ask Admin to check log!");
plugin.getLogger().severe("Could not give " + element[0] + ":" + element[1] + " to " + player.getName() + " for challenge reward!");
/*
if (element[0].equalsIgnoreCase("POTION")) {
String potionList = "";
boolean hint = false;
for (PotionEffectType m : PotionEffectType.values()) {
potionList += m.toString() + ",";
if (element[1].length() > 3) {
if (m.toString().startsWith(element[1].substring(0, 3))) {
plugin.getLogger().severe("Did you mean " + m.toString() + "?");
hint = true;
}
}
}
if (!hint) {
plugin.getLogger().severe("Sorry, I have no idea what potion type " + element[1] + " is. Pick from one of these:");
plugin.getLogger().severe(potionList.substring(0, potionList.length() - 1));
}
} else {*/
String materialList = "";
boolean hint = false;
for (Material m : Material.values()) {
materialList += m.toString() + ",";
if (m.toString().startsWith(element[0].substring(0, 3))) {
plugin.getLogger().severe("Did you mean " + m.toString() + "? If so, put that in challenges.yml.");
hint = true;
}
}
if (!hint) {
plugin.getLogger().severe("Sorry, I have no idea what " + element[0] + " is. Pick from one of these:");
plugin.getLogger().severe(materialList.substring(0, materialList.length() - 1));
}
// }
return null;
}
} else if (element.length == 6) {
// Potion format = POTION:name:level:extended:splash:qty
try {
if (StringUtils.isNumeric(element[0])) {
rewardItem = Material.getMaterial(Integer.parseInt(element[0]));
} else {
rewardItem = Material.getMaterial(element[0].toUpperCase());
}
rewardQty = Integer.parseInt(element[5]);
// Check for POTION
if (rewardItem.equals(Material.POTION)) {
givePotion(player, rewardedItems, element, rewardQty);
}
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + "There was a problem giving your reward. Ask Admin to check log!");
plugin.getLogger().severe("Problem with reward potion: " + s);
plugin.getLogger().severe("Format POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY");
plugin.getLogger().severe("LEVEL, EXTENDED and SPLASH are optional");
plugin.getLogger().severe("LEVEL is a number");
plugin.getLogger().severe("Examples:");
plugin.getLogger().severe("POTION:STRENGTH:1:EXTENDED:SPLASH:1");
plugin.getLogger().severe("POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1");
plugin.getLogger().severe("POTION:WEAKNESS:::::1 - any weakness potion");
plugin.getLogger().severe("Available names are:");
String potionNames = "";
for (PotionType p : PotionType.values()) {
potionNames += p.toString() + ", ";
}
plugin.getLogger().severe(potionNames.substring(0, potionNames.length() - 2));
return null;
}
}
}
return rewardedItems;
}
use of org.bukkit.potion.PotionType in project acidisland by tastybento.
the class Challenges method hasRequired.
/**
* Checks if a player has enough for a challenge. Supports two types of
* checks, inventory and island. Removes items if required.
*
* @param player
* @param challenge
* @param type
* @return true if the player has everything required
*/
public boolean hasRequired(final Player player, final String challenge, final String type) {
// Check money
double moneyReq = 0D;
if (Settings.useEconomy) {
moneyReq = getChallengeConfig().getDouble("challenges.challengeList." + challenge + ".requiredMoney", 0D);
if (moneyReq > 0D) {
if (!VaultHelper.econ.has(player, Settings.worldName, moneyReq)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorNotEnoughItems);
String desc = ChatColor.translateAlternateColorCodes('&', getChallengeConfig().getString("challenges.challengeList." + challenge + ".description").replace("[label]", Settings.ISLANDCOMMAND));
List<String> result = new ArrayList<String>();
if (desc.contains("|")) {
result.addAll(Arrays.asList(desc.split("\\|")));
} else {
result.add(desc);
}
for (String line : result) {
Util.sendMessage(player, ChatColor.RED + line);
}
return false;
}
}
}
final String reqList = getChallengeConfig().getString("challenges.challengeList." + challenge + ".requiredItems");
// standard items can be collected
if (type.equalsIgnoreCase("inventory")) {
List<ItemStack> toBeRemoved = new ArrayList<ItemStack>();
Material reqItem;
int reqAmount = 0;
if (!reqList.isEmpty()) {
for (final String s : reqList.split(" ")) {
final String[] part = s.split(":");
// Material:Qty
if (part.length == 2) {
try {
// Correct some common mistakes
if (part[0].equalsIgnoreCase("potato")) {
part[0] = "POTATO_ITEM";
} else if (part[0].equalsIgnoreCase("brewing_stand")) {
part[0] = "BREWING_STAND_ITEM";
} else if (part[0].equalsIgnoreCase("carrot")) {
part[0] = "CARROT_ITEM";
} else if (part[0].equalsIgnoreCase("cauldron")) {
part[0] = "CAULDRON_ITEM";
} else if (part[0].equalsIgnoreCase("skull")) {
part[0] = "SKULL_ITEM";
}
// TODO: add netherwart vs. netherstalk?
if (StringUtils.isNumeric(part[0])) {
reqItem = Material.getMaterial(Integer.parseInt(part[0]));
} else {
reqItem = Material.getMaterial(part[0].toUpperCase());
}
reqAmount = Integer.parseInt(part[1]);
ItemStack item = new ItemStack(reqItem);
if (DEBUG) {
plugin.getLogger().info("DEBUG: required item = " + reqItem.toString());
plugin.getLogger().info("DEBUG: item amount = " + reqAmount);
}
if (!player.getInventory().contains(reqItem)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: item not in inventory");
return false;
} else {
// check amount
int amount = 0;
if (DEBUG)
plugin.getLogger().info("DEBUG: Amount in inventory = " + player.getInventory().all(reqItem).size());
// enough required items
for (Entry<Integer, ? extends ItemStack> en : player.getInventory().all(reqItem).entrySet()) {
// Get the item
ItemStack i = en.getValue();
// If the item is enchanted, skip - it doesn't count
if (!i.getEnchantments().isEmpty()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: item has enchantment - doesn't count");
continue;
}
// in the same way, they need adding too...
if (i.getDurability() == 0 || (reqItem == Material.MAP && i.getType() == Material.MAP)) {
// amount += i.getAmount();
if ((amount + i.getAmount()) < reqAmount) {
// Remove all of this item stack - clone
// otherwise it will keep a reference to
// the
// original
toBeRemoved.add(i.clone());
amount += i.getAmount();
if (DEBUG)
plugin.getLogger().info("DEBUG: amount is <= req Remove " + i.toString() + ":" + i.getDurability() + " x " + i.getAmount());
} else if ((amount + i.getAmount()) == reqAmount) {
if (DEBUG)
plugin.getLogger().info("DEBUG: amount is = req Remove " + i.toString() + ":" + i.getDurability() + " x " + i.getAmount());
toBeRemoved.add(i.clone());
amount += i.getAmount();
break;
} else {
// Remove a portion of this item
if (DEBUG)
plugin.getLogger().info("DEBUG: amount is > req Remove " + i.toString() + ":" + i.getDurability() + " x " + i.getAmount());
item.setAmount(reqAmount - amount);
item.setDurability(i.getDurability());
toBeRemoved.add(item);
amount += i.getAmount();
break;
}
}
}
if (DEBUG)
plugin.getLogger().info("DEBUG: amount " + amount);
if (amount < reqAmount) {
return false;
}
}
} catch (Exception e) {
plugin.getLogger().severe("Problem with " + s + " in challenges.yml!");
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
String materialList = "";
boolean hint = false;
for (Material m : Material.values()) {
materialList += m.toString() + ",";
if (m.toString().contains(s.substring(0, 3).toUpperCase())) {
plugin.getLogger().severe("Did you mean " + m.toString() + "?");
hint = true;
}
}
if (!hint) {
plugin.getLogger().severe("Sorry, I have no idea what " + s + " is. Pick from one of these:");
plugin.getLogger().severe(materialList.substring(0, materialList.length() - 1));
} else {
plugin.getLogger().severe("Correct challenges.yml with the correct material.");
}
return false;
}
} else if (part.length == 3) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Item with durability");
// Correct some common mistakes
if (part[0].equalsIgnoreCase("potato")) {
part[0] = "POTATO_ITEM";
} else if (part[0].equalsIgnoreCase("brewing_stand")) {
part[0] = "BREWING_STAND_ITEM";
} else if (part[0].equalsIgnoreCase("carrot")) {
part[0] = "CARROT_ITEM";
} else if (part[0].equalsIgnoreCase("cauldron")) {
part[0] = "CAULDRON_ITEM";
} else if (part[0].equalsIgnoreCase("skull")) {
part[0] = "SKULL_ITEM";
}
if (StringUtils.isNumeric(part[0])) {
reqItem = Material.getMaterial(Integer.parseInt(part[0]));
} else {
reqItem = Material.getMaterial(part[0].toUpperCase());
}
reqAmount = Integer.parseInt(part[2]);
int reqDurability = Integer.parseInt(part[1]);
ItemStack item = new ItemStack(reqItem);
// Item
item.setDurability((short) reqDurability);
// check amount
int amount = 0;
// enough required items
for (Entry<Integer, ? extends ItemStack> en : player.getInventory().all(reqItem).entrySet()) {
// Get the item
ItemStack i = en.getValue();
if (i.hasItemMeta()) {
continue;
}
if (i.getDurability() == reqDurability) {
// amount += i.getAmount();
if ((amount + i.getAmount()) < reqAmount) {
// Remove all of this item stack - clone
// otherwise it will keep a reference to
// the
// original
toBeRemoved.add(i.clone());
amount += i.getAmount();
if (DEBUG)
plugin.getLogger().info("DEBUG: amount is <= req Remove " + i.toString() + ":" + i.getDurability() + " x " + i.getAmount());
} else if ((amount + i.getAmount()) == reqAmount) {
toBeRemoved.add(i.clone());
amount += i.getAmount();
break;
} else {
// Remove a portion of this item
if (DEBUG)
plugin.getLogger().info("DEBUG: amount is > req Remove " + i.toString() + ":" + i.getDurability() + " x " + i.getAmount());
item.setAmount(reqAmount - amount);
item.setDurability(i.getDurability());
toBeRemoved.add(item);
amount += i.getAmount();
break;
}
}
}
if (DEBUG) {
plugin.getLogger().info("DEBUG: amount is " + amount);
plugin.getLogger().info("DEBUG: req amount is " + reqAmount);
}
if (amount < reqAmount) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Failure! Insufficient amount of " + item.toString() + " required = " + reqAmount + " actual = " + amount);
return false;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: before set amount " + item.toString() + ":" + item.getDurability() + " x " + item.getAmount());
} else if (part.length == 6 && part[0].contains("POTION")) {
// Run through player's inventory for the item
ItemStack[] playerInv = player.getInventory().getContents();
try {
reqAmount = Integer.parseInt(part[5]);
if (DEBUG)
plugin.getLogger().info("DEBUG: required amount is " + reqAmount);
} catch (Exception e) {
plugin.getLogger().severe("Could not parse the quantity of the potion item " + s);
return false;
}
int count = reqAmount;
for (ItemStack i : playerInv) {
// Catches all POTION, LINGERING_POTION and SPLASH_POTION
if (i != null && i.getType().toString().contains("POTION")) {
// POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
// Test potion
Potion potion = null;
try {
// This may fail if there are custom potions in the player's inventory
// If so, just skip this item stack.
potion = Potion.fromItemStack(i);
} catch (Exception e) {
potion = null;
}
if (potion != null) {
PotionType potionType = potion.getType();
boolean match = true;
if (DEBUG) {
plugin.getLogger().info("DEBUG: name check " + part[1]);
plugin.getLogger().info("DEBUG: potion = " + potion);
plugin.getLogger().info("DEBUG: potionType = " + potionType);
plugin.getLogger().info("DEBUG: part[1] = " + part[1]);
}
// Name check
if (potionType != null && !part[1].isEmpty()) {
// Custom potions may not have names
if (potionType.name() != null) {
if (!part[1].equalsIgnoreCase(potionType.name())) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: name does not match");
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: name matches");
}
} else {
plugin.getLogger().severe("Potion type is unknown. Please pick from the following:");
for (PotionType pt : PotionType.values()) {
plugin.getLogger().severe(pt.name());
}
match = false;
}
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: potionType = null");
match = false;
}
// Level check (upgraded)
if (DEBUG)
plugin.getLogger().info("DEBUG: level check " + part[2]);
if (!part[2].isEmpty()) {
// There is a level declared - check it
if (StringUtils.isNumeric(part[2])) {
int level = Integer.valueOf(part[2]);
if (level != potion.getLevel()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: level does not match");
match = false;
}
}
}
// Extended check
if (DEBUG)
plugin.getLogger().info("DEBUG: extended check " + part[3]);
if (!part[3].isEmpty()) {
if (part[3].equalsIgnoreCase("EXTENDED") && !potion.hasExtendedDuration()) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: extended does not match");
}
if (part[3].equalsIgnoreCase("NOTEXTENDED") && potion.hasExtendedDuration()) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: extended does not match");
}
}
// Splash check
if (DEBUG)
plugin.getLogger().info("DEBUG: splash/linger check " + part[4]);
if (!part[4].isEmpty()) {
if (part[4].equalsIgnoreCase("SPLASH") && !potion.isSplash()) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: not splash");
}
if (part[4].equalsIgnoreCase("NOSPLASH") && potion.isSplash()) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: not no splash");
}
}
// Quantity check
if (match) {
if (DEBUG)
plugin.getLogger().info("DEBUG: potion matches!");
ItemStack removeItem = i.clone();
if (removeItem.getAmount() > reqAmount) {
if (DEBUG)
plugin.getLogger().info("DEBUG: found " + removeItem.getAmount() + " qty in inv");
removeItem.setAmount(reqAmount);
}
count = count - removeItem.getAmount();
if (DEBUG)
plugin.getLogger().info("DEBUG: " + count + " left");
toBeRemoved.add(removeItem);
}
}
} else {
// V1.9 and above
PotionMeta potionMeta = (PotionMeta) i.getItemMeta();
// If any of the settings above are missing, then any is okay
boolean match = true;
if (DEBUG)
plugin.getLogger().info("DEBUG: name check " + part[1]);
// Name check
if (!part[1].isEmpty()) {
// There is a name
if (PotionType.valueOf(part[1]) != null) {
if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(part[1])) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: name does not match");
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: name matches");
}
} else {
plugin.getLogger().severe("Potion type is unknown. Please pick from the following:");
for (PotionType pt : PotionType.values()) {
plugin.getLogger().severe(pt.name());
}
match = false;
}
}
// plugin.getLogger().info("DEBUG: level check " + part[2]);
if (!part[2].isEmpty()) {
// There is a level declared - check it
if (StringUtils.isNumeric(part[2])) {
int level = Integer.valueOf(part[2]);
if (level == 1 && potionMeta.getBasePotionData().isUpgraded()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: level does not match");
match = false;
}
if (level != 1 && !potionMeta.getBasePotionData().isUpgraded()) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: level does not match");
}
}
}
// Extended check
if (DEBUG)
plugin.getLogger().info("DEBUG: extended check " + part[3]);
if (!part[3].isEmpty()) {
if (part[3].equalsIgnoreCase("EXTENDED") && !potionMeta.getBasePotionData().isExtended()) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: extended does not match");
}
if (part[3].equalsIgnoreCase("NOTEXTENDED") && potionMeta.getBasePotionData().isExtended()) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: extended does not match");
}
}
// Splash or Linger check
if (DEBUG)
plugin.getLogger().info("DEBUG: splash/linger check " + part[4]);
if (!part[4].isEmpty()) {
if (part[4].equalsIgnoreCase("SPLASH") && !i.getType().equals(Material.SPLASH_POTION)) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: not splash");
}
if (part[4].equalsIgnoreCase("NOSPLASH") && i.getType().equals(Material.SPLASH_POTION)) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: not no splash");
}
if (part[4].equalsIgnoreCase("LINGER") && !i.getType().equals(Material.LINGERING_POTION)) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: not linger");
}
if (part[4].equalsIgnoreCase("NOLINGER") && i.getType().equals(Material.LINGERING_POTION)) {
match = false;
if (DEBUG)
plugin.getLogger().info("DEBUG: not no linger");
}
}
// Quantity check
if (match) {
if (DEBUG)
plugin.getLogger().info("DEBUG: potion matches!");
ItemStack removeItem = i.clone();
if (removeItem.getAmount() > reqAmount) {
if (DEBUG)
plugin.getLogger().info("DEBUG: found " + removeItem.getAmount() + " qty in inv");
removeItem.setAmount(reqAmount);
}
count = count - removeItem.getAmount();
if (DEBUG)
plugin.getLogger().info("DEBUG: " + count + " left");
toBeRemoved.add(removeItem);
}
}
}
if (count <= 0) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Player has enough");
break;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: still need " + count + " to complete");
}
if (count > 0) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Player does not have enough");
return false;
}
} else {
plugin.getLogger().severe("Problem with " + s + " in challenges.yml!");
return false;
}
}
}
if (getChallengeConfig().getBoolean("challenges.challengeList." + challenge + ".takeItems")) {
// int qty = 0;
if (DEBUG)
plugin.getLogger().info("DEBUG: Removing items");
for (ItemStack i : toBeRemoved) {
// qty += i.getAmount();
if (DEBUG)
plugin.getLogger().info("DEBUG: Remove " + i.toString() + "::" + i.getDurability() + " x " + i.getAmount());
HashMap<Integer, ItemStack> leftOver = player.getInventory().removeItem(i);
if (!leftOver.isEmpty()) {
plugin.getLogger().warning("Exploit? Could not remove the following in challenge " + challenge + " for player " + player.getName() + ":");
for (ItemStack left : leftOver.values()) {
plugin.getLogger().info(left.toString());
}
return false;
}
}
// Remove money
if (moneyReq > 0D) {
EconomyResponse er = VaultHelper.econ.withdrawPlayer(player, moneyReq);
if (!er.transactionSuccess()) {
plugin.getLogger().warning("Exploit? Could not remove " + VaultHelper.econ.format(moneyReq) + " from " + player.getName() + " in challenge " + challenge);
plugin.getLogger().warning("Player's balance is " + VaultHelper.econ.format(VaultHelper.econ.getBalance(player)));
}
}
// plugin.getLogger().info("DEBUG: total = " + qty);
}
return true;
}
if (type.equalsIgnoreCase("island")) {
final HashMap<MaterialData, Integer> neededItem = new HashMap<MaterialData, Integer>();
final HashMap<EntityType, Integer> neededEntities = new HashMap<EntityType, Integer>();
if (!reqList.isEmpty()) {
for (int i = 0; i < reqList.split(" ").length; i++) {
final String[] sPart = reqList.split(" ")[i].split(":");
try {
// Find out if the needed item is a Material or an Entity
boolean isEntity = false;
for (EntityType entityType : EntityType.values()) {
if (entityType.toString().equalsIgnoreCase(sPart[0])) {
isEntity = true;
break;
}
}
if (isEntity) {
// plugin.getLogger().info("DEBUG: Item " + sPart[0].toUpperCase() + " is an entity");
EntityType entityType = EntityType.valueOf(sPart[0].toUpperCase());
if (entityType != null) {
neededEntities.put(entityType, Integer.parseInt(sPart[1]));
// plugin.getLogger().info("DEBUG: Needed entity is " + Integer.parseInt(sPart[1]) + " x " + EntityType.valueOf(sPart[0].toUpperCase()).toString());
}
} else {
Material item;
if (StringUtils.isNumeric(sPart[0])) {
item = Material.getMaterial(Integer.parseInt(sPart[0]));
} else {
item = Material.getMaterial(sPart[0].toUpperCase());
}
if (item != null) {
// We have two cases : quantity only OR durability + quantity
final int quantity;
final byte durability;
if (sPart.length == 2) {
// Only a quantity is specified
quantity = Integer.parseInt(sPart[1]);
durability = 0;
} else {
quantity = Integer.parseInt(sPart[2]);
durability = Byte.parseByte(sPart[1]);
}
neededItem.put(new MaterialData(item, durability), quantity);
// plugin.getLogger().info("DEBUG: Needed item is " + Integer.parseInt(sPart[1]) + " x " + Material.getMaterial(sPart[0]).toString());
} else {
plugin.getLogger().warning("Problem parsing required item for challenge " + challenge + " in challenges.yml!");
return false;
}
}
} catch (Exception intEx) {
plugin.getLogger().warning("Problem parsing required items for challenge " + challenge + " in challenges.yml - skipping");
return false;
}
}
}
// We now have two sets of required items or entities
// Check the items first
final Location l = player.getLocation();
// if (!neededItem.isEmpty()) {
final int px = l.getBlockX();
final int py = l.getBlockY();
final int pz = l.getBlockZ();
// Get search radius - min is 10, max is 50
int searchRadius = getChallengeConfig().getInt("challenges.challengeList." + challenge + ".searchRadius", 10);
if (searchRadius < 10) {
searchRadius = 10;
} else if (searchRadius > 50) {
searchRadius = 50;
}
for (int x = -searchRadius; x <= searchRadius; x++) {
for (int y = -searchRadius; y <= searchRadius; y++) {
for (int z = -searchRadius; z <= searchRadius; z++) {
final MaterialData b = new Location(l.getWorld(), px + x, py + y, pz + z).getBlock().getState().getData();
if (neededItem.containsKey(b)) {
if (neededItem.get(b) == 1) {
neededItem.remove(b);
} else {
// Reduce the require amount by 1
neededItem.put(b, neededItem.get(b) - 1);
}
}
}
}
}
// Check if all the needed items have been amassed
if (!neededItem.isEmpty()) {
// plugin.getLogger().info("DEBUG: Insufficient items around");
for (MaterialData missing : neededItem.keySet()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorYouAreMissing + " " + neededItem.get(missing) + " x " + Util.prettifyText(missing.getItemType().toString()) + ":" + missing.getData());
}
return false;
} else {
// Check for needed entities
for (Entity entity : player.getNearbyEntities(searchRadius, searchRadius, searchRadius)) {
// entity.getType().toString());
if (neededEntities.containsKey(entity.getType())) {
// plugin.getLogger().info("DEBUG: Entity in list");
if (neededEntities.get(entity.getType()) == 1) {
neededEntities.remove(entity.getType());
// plugin.getLogger().info("DEBUG: Entity qty satisfied");
} else {
neededEntities.put(entity.getType(), neededEntities.get(entity.getType()) - 1);
// plugin.getLogger().info("DEBUG: Entity qty reduced by 1");
}
} else {
// plugin.getLogger().info("DEBUG: Entity not in list");
}
}
if (neededEntities.isEmpty()) {
return true;
} else {
for (EntityType missing : neededEntities.keySet()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorYouAreMissing + " " + neededEntities.get(missing) + " x " + Util.prettifyText(missing.toString()));
}
return false;
}
}
}
return true;
}
use of org.bukkit.potion.PotionType in project acidisland by tastybento.
the class IslandCmd method loadSchematics.
/**
* Loads schematics from the config.yml file. If the default
* island is not included, it will be made up
*/
public void loadSchematics() {
// Check if there is a schematic folder and make it if it does not exist
File schematicFolder = new File(plugin.getDataFolder(), "schematics");
if (!schematicFolder.exists()) {
schematicFolder.mkdir();
}
// Clear the schematic list that is kept in memory
schematics.clear();
// Load the default schematic if it exists
// Set up the default schematic
File schematicFile = new File(schematicFolder, "island.schematic");
File netherFile = new File(schematicFolder, "nether.schematic");
if (!schematicFile.exists()) {
// Only copy if the default exists
if (plugin.getResource("schematics/island.schematic") != null) {
plugin.getLogger().info("Default schematic does not exist, saving it...");
plugin.saveResource("schematics/island.schematic", false);
// Add it to schematics
try {
schematics.put("default", new Schematic(plugin, schematicFile));
} catch (IOException e) {
plugin.getLogger().severe("Could not load default schematic!");
e.printStackTrace();
}
// If this is repeated later due to the schematic config, fine, it will only add info
} else {
// No islands.schematic in the jar, so just make the default using
// built-in island generation
schematics.put("default", new Schematic(plugin));
}
plugin.getLogger().info("Loaded default nether schematic");
} else {
// It exists, so load it
try {
schematics.put("default", new Schematic(plugin, schematicFile));
plugin.getLogger().info("Loaded default island schematic.");
} catch (IOException e) {
plugin.getLogger().severe("Could not load default schematic!");
e.printStackTrace();
}
}
// Add the nether default too
if (!netherFile.exists()) {
if (plugin.getResource("schematics/nether.schematic") != null) {
plugin.saveResource("schematics/nether.schematic", false);
// Add it to schematics
try {
Schematic netherIsland = new Schematic(plugin, netherFile);
netherIsland.setVisible(false);
schematics.put("nether", netherIsland);
plugin.getLogger().info("Loaded default nether schematic.");
} catch (IOException e) {
plugin.getLogger().severe("Could not load default nether schematic!");
e.printStackTrace();
}
} else {
plugin.getLogger().severe("Could not find default nether schematic!");
}
} else {
// It exists, so load it
try {
Schematic netherIsland = new Schematic(plugin, netherFile);
netherIsland.setVisible(false);
schematics.put("nether", netherIsland);
plugin.getLogger().info("Loaded default nether schematic.");
} catch (IOException e) {
plugin.getLogger().severe("Could not load default nether schematic!");
e.printStackTrace();
}
}
// Set up some basic settings just in case the schematics section is missing
if (schematics.containsKey("default")) {
schematics.get("default").setIcon(Material.GRASS);
schematics.get("default").setOrder(1);
schematics.get("default").setName("The Original");
schematics.get("default").setDescription("");
schematics.get("default").setPartnerName("nether");
schematics.get("default").setBiome(Settings.defaultBiome);
schematics.get("default").setIcon(Material.GRASS);
if (Settings.chestItems.length == 0) {
schematics.get("default").setUseDefaultChest(false);
} else {
schematics.get("default").setUseDefaultChest(true);
}
}
if (schematics.containsKey("nether")) {
schematics.get("nether").setName("NetherBlock Island");
schematics.get("nether").setDescription("Nether Island");
schematics.get("nether").setPartnerName("default");
schematics.get("nether").setBiome(Biome.HELL);
schematics.get("nether").setIcon(Material.NETHERRACK);
schematics.get("nether").setVisible(false);
schematics.get("nether").setPasteEntities(true);
if (Settings.chestItems.length == 0) {
schematics.get("nether").setUseDefaultChest(false);
}
}
// Load the schematics from config.yml
ConfigurationSection schemSection = plugin.getConfig().getConfigurationSection("schematicsection");
if (plugin.getConfig().contains("schematicsection")) {
Settings.useSchematicPanel = schemSection.getBoolean("useschematicspanel", false);
Settings.chooseIslandRandomly = schemSection.getBoolean("chooseislandrandomly", false);
ConfigurationSection schematicsSection = schemSection.getConfigurationSection("schematics");
// Section exists, so go through the various sections
for (String key : schematicsSection.getKeys(false)) {
try {
Schematic newSchem = null;
// Check the file exists
// plugin.getLogger().info("DEBUG: schematics." + key + ".filename" );
String filename = schemSection.getString("schematics." + key + ".filename", "");
if (!filename.isEmpty()) {
// plugin.getLogger().info("DEBUG: filename = " + filename);
// Check if this file exists or if it is in the jar
schematicFile = new File(schematicFolder, filename);
// See if the file exists
if (schematicFile.exists()) {
newSchem = new Schematic(plugin, schematicFile);
} else if (plugin.getResource("schematics/" + filename) != null) {
plugin.saveResource("schematics/" + filename, false);
newSchem = new Schematic(plugin, schematicFile);
}
} else {
// plugin.getLogger().info("DEBUG: filename is empty");
if (key.equalsIgnoreCase("default")) {
// Øplugin.getLogger().info("DEBUG: key is default, so use this one");
newSchem = schematics.get("default");
} else {
plugin.getLogger().severe("Schematic " + key + " does not have a filename. Skipping!");
}
}
if (newSchem != null) {
// Set the heading
newSchem.setHeading(key);
// Order
newSchem.setOrder(schemSection.getInt("schematics." + key + ".order", 0));
// Icon
try {
Material icon;
String iconString = schemSection.getString("schematics." + key + ".icon", "MAP").toUpperCase();
// Support damage values
String[] split = iconString.split(":");
if (StringUtils.isNumeric(split[0])) {
icon = Material.getMaterial(Integer.parseInt(split[0]));
if (icon == null) {
icon = Material.MAP;
plugin.getLogger().severe("Schematic's icon could not be found. Try using quotes like '17:2'");
}
} else {
icon = Material.valueOf(split[0]);
}
int damage = 0;
if (split.length == 2) {
if (StringUtils.isNumeric(split[1])) {
damage = Integer.parseInt(split[1]);
}
}
newSchem.setIcon(icon, damage);
} catch (Exception e) {
// e.printStackTrace();
newSchem.setIcon(Material.MAP);
}
// Friendly name
String name = ChatColor.translateAlternateColorCodes('&', schemSection.getString("schematics." + key + ".name", ""));
newSchem.setName(name);
// Rating - Rating is not used right now
int rating = schemSection.getInt("schematics." + key + ".rating", 50);
if (rating < 1) {
rating = 1;
} else if (rating > 100) {
rating = 100;
}
newSchem.setRating(rating);
// Cost
double cost = schemSection.getDouble("schematics." + key + ".cost", 0D);
if (cost < 0) {
cost = 0;
}
newSchem.setCost(cost);
// Description
String description = ChatColor.translateAlternateColorCodes('&', schemSection.getString("schematics." + key + ".description", ""));
description = description.replace("[rating]", String.valueOf(rating));
if (Settings.useEconomy) {
description = description.replace("[cost]", String.valueOf(cost));
}
newSchem.setDescription(description);
// Permission
String perm = schemSection.getString("schematics." + key + ".permission", "");
newSchem.setPerm(perm);
// Use default chest
newSchem.setUseDefaultChest(schemSection.getBoolean("schematics." + key + ".useDefaultChest", true));
// Biomes - overrides default if it exists
String biomeString = schemSection.getString("schematics." + key + ".biome", Settings.defaultBiome.toString());
Biome biome = null;
try {
biome = Biome.valueOf(biomeString);
newSchem.setBiome(biome);
} catch (Exception e) {
plugin.getLogger().severe("Could not parse biome " + biomeString + " using default instead.");
}
// Use physics - overrides default if it exists
newSchem.setUsePhysics(schemSection.getBoolean("schematics." + key + ".usephysics", Settings.usePhysics));
// Paste Entities or not
newSchem.setPasteEntities(schemSection.getBoolean("schematics." + key + ".pasteentities", false));
// Paste air or not. Default is false - huge performance savings!
// newSchem.setPasteAir(schemSection.getBoolean("schematics." + key + ".pasteair",false));
// Visible in GUI or not
newSchem.setVisible(schemSection.getBoolean("schematics." + key + ".show", true));
// Partner schematic
if (biome != null && biome.equals(Biome.HELL)) {
// Default for nether biomes is the default overworld island
newSchem.setPartnerName(schemSection.getString("schematics." + key + ".partnerSchematic", "default"));
} else {
// Default for overworld biomes is nether island
newSchem.setPartnerName(schemSection.getString("schematics." + key + ".partnerSchematic", "nether"));
}
// Island companion
List<String> companion = schemSection.getStringList("schematics." + key + ".companion");
List<EntityType> companionTypes = new ArrayList<EntityType>();
if (!companion.isEmpty()) {
for (String companionType : companion) {
companionType = companionType.toUpperCase();
if (companionType.equalsIgnoreCase("NOTHING")) {
companionTypes.add(null);
} else {
try {
EntityType type = EntityType.valueOf(companionType);
companionTypes.add(type);
} catch (Exception e) {
plugin.getLogger().warning("Island companion is not recognized in schematic '" + name + "'.");
}
}
}
newSchem.setIslandCompanion(companionTypes);
}
// Companion names
List<String> companionNames = schemSection.getStringList("schematics." + key + ".companionnames");
if (!companionNames.isEmpty()) {
List<String> names = new ArrayList<String>();
for (String companionName : companionNames) {
names.add(ChatColor.translateAlternateColorCodes('&', companionName));
}
newSchem.setCompanionNames(names);
}
// Get chest items
final List<String> chestItems = schemSection.getStringList("schematics." + key + ".chestItems");
if (!chestItems.isEmpty()) {
ItemStack[] tempChest = new ItemStack[chestItems.size()];
int i = 0;
for (String chestItemString : chestItems) {
// plugin.getLogger().info("DEBUG: chest item = " + chestItemString);
try {
String[] amountdata = chestItemString.split(":");
if (amountdata[0].equals("POTION")) {
if (amountdata.length == 3) {
Potion chestPotion = new Potion(PotionType.valueOf(amountdata[1]));
tempChest[i++] = chestPotion.toItemStack(Integer.parseInt(amountdata[2]));
} else if (amountdata.length == 4) {
// Extended or splash potions
if (amountdata[2].equals("EXTENDED")) {
Potion chestPotion = new Potion(PotionType.valueOf(amountdata[1])).extend();
tempChest[i++] = chestPotion.toItemStack(Integer.parseInt(amountdata[3]));
} else if (amountdata[2].equals("SPLASH")) {
Potion chestPotion = new Potion(PotionType.valueOf(amountdata[1])).splash();
tempChest[i++] = chestPotion.toItemStack(Integer.parseInt(amountdata[3]));
} else if (amountdata[2].equals("EXTENDEDSPLASH")) {
Potion chestPotion = new Potion(PotionType.valueOf(amountdata[1])).extend().splash();
tempChest[i++] = chestPotion.toItemStack(Integer.parseInt(amountdata[3]));
}
}
} else {
Material mat;
if (StringUtils.isNumeric(amountdata[0])) {
mat = Material.getMaterial(Integer.parseInt(amountdata[0]));
} else {
mat = Material.getMaterial(amountdata[0].toUpperCase());
}
if (amountdata.length == 2) {
tempChest[i++] = new ItemStack(mat, Integer.parseInt(amountdata[1]));
} else if (amountdata.length == 3) {
tempChest[i++] = new ItemStack(mat, Integer.parseInt(amountdata[2]), Short.parseShort(amountdata[1]));
}
}
} catch (java.lang.IllegalArgumentException ex) {
plugin.getLogger().severe("Problem loading chest item for schematic '" + name + "' so skipping it: " + chestItemString);
plugin.getLogger().severe("Error is : " + ex.getMessage());
plugin.getLogger().info("Potential potion types are: ");
for (PotionType c : PotionType.values()) plugin.getLogger().info(c.name());
} catch (Exception e) {
plugin.getLogger().severe("Problem loading chest item for schematic '" + name + "' so skipping it: " + chestItemString);
plugin.getLogger().info("Potential material types are: ");
for (Material c : Material.values()) plugin.getLogger().info(c.name());
// e.printStackTrace();
}
}
// Store it
newSchem.setDefaultChestItems(tempChest);
}
// Player spawn block
String spawnBlock = schemSection.getString("schematics." + key + ".spawnblock");
if (spawnBlock != null) {
// Check to see if this block is a valid material
try {
Material playerSpawnBlock;
if (StringUtils.isNumeric(spawnBlock)) {
playerSpawnBlock = Material.getMaterial(Integer.parseInt(spawnBlock));
} else {
playerSpawnBlock = Material.valueOf(spawnBlock.toUpperCase());
}
if (newSchem.setPlayerSpawnBlock(playerSpawnBlock)) {
plugin.getLogger().info("Player will spawn at the " + playerSpawnBlock.toString());
} else {
plugin.getLogger().severe("Problem with schematic '" + name + "'. Spawn block '" + spawnBlock + "' not found in schematic or there is more than one. Skipping...");
}
} catch (Exception e) {
plugin.getLogger().severe("Problem with schematic '" + name + "'. Spawn block '" + spawnBlock + "' is unknown. Skipping...");
}
} else {
// plugin.getLogger().info("No spawn block found");
}
// Level handicap
newSchem.setLevelHandicap(schemSection.getInt("schematics." + key + ".levelHandicap", 0));
// Store it
schematics.put(key, newSchem);
if (perm.isEmpty()) {
perm = "all players";
} else {
perm = "player with " + perm + " permission";
}
plugin.getLogger().info("Loading schematic " + name + " (" + filename + ") for " + perm + ", order " + newSchem.getOrder());
} else {
plugin.getLogger().warning("Could not find " + filename + " in the schematics folder! Skipping...");
}
} catch (IOException e) {
plugin.getLogger().info("Error loading schematic in section " + key + ". Skipping...");
}
}
if (schematics.isEmpty()) {
tip();
}
}
}
Aggregations