Skip to content

Commit

Permalink
Improved chest potion handling further.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 9, 2016
1 parent a51e435 commit a57b07a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ island:
# LINGER is for V1.9 servers and later
# Examples:
# POTION:STRENGTH:1:EXTENDED:SPLASH:1
# POTION:INSTANT_HARM:2::LINGER:2
# POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1
# POTION:INSTANT_DAMAGE:2::LINGER:2
# POTION:JUMP:2:::1
# POTION:WEAKNESS::::1 - any weakness potion
#
# Valid potion names are:
Expand Down
2 changes: 1 addition & 1 deletion src/com/wasteofplastic/askyblock/ASkyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ public boolean loadPluginConfig() {
// getLogger().info("DEBUG: Potion length " +
// amountdata.length);
if (amountdata.length == 6) {
tempChest[i] = Challenges.getPotion(amountdata, Integer.parseInt(amountdata[5]));
tempChest[i] = Challenges.getPotion(amountdata, Integer.parseInt(amountdata[5]), "config.yml");
} else {
getLogger().severe("Problem loading chest item from config.yml so skipping it: " + chestItemString[i]);
getLogger().severe("Potions for the chest must be fully defined as POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY");
Expand Down
24 changes: 18 additions & 6 deletions src/com/wasteofplastic/askyblock/commands/Challenges.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,14 @@ private List<ItemStack> giveItems(Player player, String[] itemRewards) {
return rewardedItems;
}

public static ItemStack getPotion(String[] element, int rewardQty) {
/**
* Converts a serialized potion to a ItemStack of that potion
* @param element
* @param rewardQty
* @param configFile that is being used
* @return ItemStack of the potion
*/
public static ItemStack getPotion(String[] element, int rewardQty, String configFile) {
// Check for potion aspects
boolean splash = false;
boolean extended = false;
Expand Down Expand Up @@ -616,7 +623,11 @@ public static ItemStack getPotion(String[] element, int rewardQty) {
// Add the effect of the potion
final PotionType potionType = PotionType.valueOf(element[1]);
if (potionType == null) {
Bukkit.getLogger().severe("Potion effect '" + element[1] + "' in challenges.yml is unknown - skipping!");
Bukkit.getLogger().severe("Potion effect '" + element[1] + "' in " + configFile + " is unknown - skipping!");
Bukkit.getLogger().severe("Use one of the following:");
for (PotionType name : PotionType.values()) {
Bukkit.getLogger().severe(name.name());
}
} else {
final Potion rewPotion = new Potion(potionType);
if (potionType != PotionType.INSTANT_DAMAGE && potionType != PotionType.INSTANT_HEAL) {
Expand All @@ -637,7 +648,8 @@ public static ItemStack getPotion(String[] element, int rewardQty) {
rewPotion.setLinger(linger);
return rewPotion.toItemStack(rewardQty);
} catch (Exception e) {
Bukkit.getLogger().severe("Reward potion effect type in config.yml challenges is unknown - skipping!");
Bukkit.getLogger().severe("Potion effect '" + element[1] + "' in " + configFile + " is unknown - skipping!");
Bukkit.getLogger().severe("Use one of the following:");
for (Potion1_9.PotionType name : Potion1_9.PotionType.values()) {
Bukkit.getLogger().severe(name.name());
}
Expand All @@ -647,7 +659,7 @@ public static ItemStack getPotion(String[] element, int rewardQty) {
}

private void givePotion(Player player, List<ItemStack> rewardedItems, String[] element, int rewardQty) {
ItemStack item = getPotion(element, rewardQty);
ItemStack item = getPotion(element, rewardQty, "challenges.yml");
rewardedItems.add(item);
final HashMap<Integer, ItemStack> leftOvers = player.getInventory().addItem(item);
if (!leftOvers.isEmpty()) {
Expand Down Expand Up @@ -1036,7 +1048,7 @@ public boolean hasRequired(final Player player, final String challenge, final St
// Check for potions
if (reqItem.equals(Material.POTION)) {
//Logger.logger(2,"DEBUG: Potion");
item = getPotion(part,1);
item = getPotion(part,1, "challenges.yml");

// Contains at least does not work for potions
ItemStack[] playerInv = player.getInventory().getContents();
Expand Down Expand Up @@ -1208,7 +1220,7 @@ public boolean hasRequired(final Player player, final String challenge, final St
if (reqItem == Material.POTION) {
//plugin.getLogger().info("DEBUG: required item is a potion");
// This gets the correct potion
item = getPotion(part, reqAmount);
item = getPotion(part, reqAmount, "challenges.yml");
if (item != null) {
ItemStack[] playerInv = player.getInventory().getContents();
for (ItemStack i : playerInv) {
Expand Down

0 comments on commit a57b07a

Please sign in to comment.