mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-08 08:48:02 +01:00
Add option to ignore Item lore in challenges
This commit is contained in:
parent
a41b7d27b4
commit
b1be709c3c
@ -5,6 +5,7 @@ import com.songoda.core.hooks.EconomyManager;
|
|||||||
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.island.Island;
|
import com.songoda.skyblock.island.Island;
|
||||||
|
import com.songoda.skyblock.utils.item.ItemStackUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -16,6 +17,7 @@ import org.bukkit.inventory.meta.PotionMeta;
|
|||||||
import org.bukkit.potion.PotionData;
|
import org.bukkit.potion.PotionData;
|
||||||
import org.bukkit.potion.PotionType;
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -149,20 +151,40 @@ public class Challenge {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean has(Player p, Object obj) {
|
public boolean has(Player p, Object obj) {
|
||||||
|
boolean ignoreLore = SkyBlock.getInstance().getFileManager()
|
||||||
|
.getConfig(new File(SkyBlock.getInstance().getDataFolder(), "config.yml"))
|
||||||
|
.getFileConfiguration().getBoolean("Island.Challenge.IgnoreItemLore", false);
|
||||||
|
if(obj instanceof ItemStack){
|
||||||
// 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){
|
||||||
|
return p.getInventory().contains(is.getType(), is.getAmount());
|
||||||
|
}
|
||||||
return p.getInventory().containsAtLeast(new ItemStack(is.getType()), is.getAmount());
|
return p.getInventory().containsAtLeast(new ItemStack(is.getType()), is.getAmount());
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeRequire(Player p, Object obj) {
|
public void executeRequire(Player p, Object obj) {
|
||||||
|
boolean ignoreLore = SkyBlock.getInstance().getFileManager()
|
||||||
|
.getConfig(new File(SkyBlock.getInstance().getDataFolder(), "config.yml"))
|
||||||
|
.getFileConfiguration().getBoolean("Island.Challenge.IgnoreItemLore", false);
|
||||||
|
|
||||||
if(obj instanceof ItemStack){
|
if(obj instanceof ItemStack){
|
||||||
// Remove specific item in player's inventory
|
// Remove specific item in player's inventory
|
||||||
ItemStack is = (ItemStack) obj;
|
ItemStack is = (ItemStack) obj;
|
||||||
//p.getInventory().removeItem(new ItemStack(is.getType(), is.getAmount()));
|
|
||||||
int toRemove = is.getAmount();
|
int toRemove = is.getAmount();
|
||||||
for(ItemStack jis : p.getInventory().getContents()) {
|
for(ItemStack jis : p.getInventory().getContents()) {
|
||||||
if(jis != null && jis.isSimilar(is)) {
|
if(jis != null) {
|
||||||
|
boolean isItem;
|
||||||
|
if(ignoreLore){
|
||||||
|
isItem = jis.getType().equals(is.getType());
|
||||||
|
} else {
|
||||||
|
isItem = jis.isSimilar(is);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isItem) {
|
||||||
if(jis.getAmount() <= toRemove) {
|
if(jis.getAmount() <= toRemove) {
|
||||||
toRemove -= jis.getAmount();
|
toRemove -= jis.getAmount();
|
||||||
jis.setAmount(0);
|
jis.setAmount(0);
|
||||||
@ -177,7 +199,7 @@ public class Challenge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO LOG
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -188,7 +210,6 @@ public class Challenge {
|
|||||||
.addItem(new ItemStack(is.getType(), is.getAmount()));
|
.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);
|
||||||
// TODO LOG
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
CMD {
|
CMD {
|
||||||
|
@ -331,8 +331,10 @@ Island:
|
|||||||
Challenge:
|
Challenge:
|
||||||
# Enable or disable challenges. Configuration for challenges are in challenges.yml file
|
# Enable or disable challenges. Configuration for challenges are in challenges.yml file
|
||||||
Enable: true
|
Enable: true
|
||||||
# Disabling this will make challenges per player
|
# Whether challenges should be per-island or per-player
|
||||||
PerIsland: true
|
PerIsland: false
|
||||||
|
# Whether to ignore item lore in requirements
|
||||||
|
IgnoreItemLore: false
|
||||||
Teleport:
|
Teleport:
|
||||||
# Enable or disable Fall damage
|
# Enable or disable Fall damage
|
||||||
FallDamage: true
|
FallDamage: true
|
||||||
|
Loading…
Reference in New Issue
Block a user