Challenges utilizing complex items should work on 1.12.

This commit is contained in:
Brianna 2020-09-01 15:10:35 -05:00
parent 82ad0e69a3
commit b830cd7637

View File

@ -2,6 +2,7 @@ package com.songoda.skyblock.challenge.challenge;
import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.hooks.economies.Economy; import com.songoda.core.hooks.economies.Economy;
import com.songoda.core.utils.ItemUtils;
import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.bank.BankManager; import com.songoda.skyblock.bank.BankManager;
import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager;
@ -189,7 +190,7 @@ public class Challenge {
// The id // The id
String id = index == -1 ? value : value.substring(0, index); String id = index == -1 ? value : value.substring(0, index);
// Check if it's a Minecraft item // Check if it's a Minecraft item
Material m = CompatibleMaterial.getMaterial(id).getMaterial(); CompatibleMaterial m = CompatibleMaterial.getMaterial(id);
//Material m = Material.matchMaterial(id); //Material m = Material.matchMaterial(id);
if (m == null) if (m == null)
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -204,7 +205,9 @@ public class Challenge {
"\"" + strAmount + "\" isn't a correct number (value = \"" + value + "\")"); "\"" + strAmount + "\" isn't a correct number (value = \"" + value + "\")");
} }
} }
return new ItemStack(m, amount); ItemStack item = m.getItem();
item.setAmount(amount);
return item;
} }
@Override @Override
@ -214,54 +217,46 @@ public class Challenge {
// Check if player has specific item in his inventory // Check if player has specific item in his inventory
ItemStack is = (ItemStack) obj; ItemStack is = (ItemStack) obj;
if(ignoreLore){ if(ignoreLore){
return p.getInventory().contains(is.getType(), is.getAmount()); return p.getInventory().contains(is, is.getAmount());
} }
return p.getInventory().containsAtLeast(new ItemStack(is.getType()), is.getAmount()); return p.getInventory().containsAtLeast(is, is.getAmount());
} }
return false; return false;
} }
@Override
public void executeRequire(Player p, Object obj) {
boolean ignoreLore = SkyBlock.getInstance().getConfiguration().getBoolean("Island.Challenge.IgnoreItemLore", false);
if(obj instanceof ItemStack){ @Override
// Remove specific item in player's inventory public void executeRequire(Player p, Object obj) {
ItemStack is = (ItemStack) obj; boolean ignoreLore = SkyBlock.getInstance().getConfig().getBoolean("Island.Challenge.IgnoreItemLore", false);
int toRemove = is.getAmount();
for(ItemStack jis : p.getInventory().getContents()) {
if(jis != null) {
boolean isItem;
if(ignoreLore){
isItem = jis.getType().equals(is.getType());
} else {
isItem = jis.isSimilar(is);
}
if(isItem) { if (obj instanceof ItemStack) {
if(jis.getAmount() <= toRemove) { // Remove specific item in player's inventory
toRemove -= jis.getAmount(); ItemStack is = (ItemStack) obj;
p.getInventory().removeItem(jis); int toRemove = is.getAmount();
} else { for (ItemStack jis : p.getInventory().getContents()) {
jis.setAmount(jis.getAmount() - toRemove); if (jis == null) continue;
toRemove = 0; if (ignoreLore ? ItemUtils.isSimilarMaterial(is, jis) : jis.isSimilar(is)) {
} if (jis.getAmount() <= toRemove) {
} toRemove -= jis.getAmount();
if(toRemove <= 0) { p.getInventory().removeItem(jis);
p.updateInventory(); } else {
break; jis.setAmount(jis.getAmount() - toRemove);
} toRemove = 0;
} }
} }
} if (toRemove <= 0) {
} p.updateInventory();
break;
}
}
}
}
@Override @Override
public void executeReward(Player p, Object obj) { public void executeReward(Player p, Object obj) {
// Give specific item to player // Give specific item to player
ItemStack is = (ItemStack) obj; ItemStack is = (ItemStack) obj;
HashMap<Integer, ItemStack> rest = p.getInventory() HashMap<Integer, ItemStack> rest = p.getInventory().addItem(is.clone());
.addItem(new ItemStack(is.getType(), is.getAmount()));
for (ItemStack restIs : rest.values()) for (ItemStack restIs : rest.values())
p.getWorld().dropItem(p.getLocation(), restIs); p.getWorld().dropItem(p.getLocation(), restIs);
} }