package pl.blacksquad.mhcore.data.base.drops;
import java.util.*;
import org.bukkit.block.*;
import org.bukkit.entity.*;
import org.bukkit.inventory.*;
import pl.blacksquad.mhcore.managers.*;
import pl.blacksquad.mhapi.*;
import org.bukkit.enchantments.*;
import pl.blacksquad.mhcore.utils.*;
import org.bukkit.command.*;
import org.bukkit.*;
import pl.blacksquad.mhcore.data.base.user.*;
import pl.blacksquad.mhcore.data.base.guild.*;
public class RandomDropData implements DropData
{
public static final List<Drop> drops;
private static final Set<UUID> noCobble;
private static final Set<UUID> noMsg;
private static final Set<UUID> noEq;
private static List<String> eq;
static {
RandomDropData.eq = new ArrayList<String>();
drops = new ArrayList<Drop>();
noCobble = new HashSet<UUID>();
noMsg = new HashSet<UUID>();
noEq = new HashSet<UUID>();
}
public static void changeNoCobble(final UUID uuid) {
if (RandomDropData.noCobble.contains(uuid)) {
RandomDropData.noCobble.remove(uuid);
}
else {
RandomDropData.noCobble.add(uuid);
}
}
public static void changeNoEq(final UUID uuid) {
if (RandomDropData.noEq.contains(uuid)) {
RandomDropData.noEq.remove(uuid);
}
else {
RandomDropData.noEq.add(uuid);
}
}
public static void disableEq(final String player) {
if (!RandomDropData.eq.contains(player.toLowerCase())) {
RandomDropData.eq.add(player.toLowerCase());
}
}
public static void enableEq(final String player) {
if (RandomDropData.eq.contains(player.toLowerCase())) {
RandomDropData.eq.remove(player.toLowerCase());
}
}
public static boolean isNoMsg(final UUID uuid) {
return RandomDropData.noMsg.contains(uuid);
}
public static boolean isEq(final String player) {
return !RandomDropData.eq.contains(player.toLowerCase());
}
public static void changeNoMsg(final UUID uuid) {
if (RandomDropData.noMsg.contains(uuid)) {
RandomDropData.noMsg.remove(uuid);
}
else {
RandomDropData.noMsg.add(uuid);
}
}
public static boolean isNoCobble(final UUID uuid) {
return RandomDropData.noCobble.contains(uuid);
}
public RandomDropData() {
RandomDropData.drops.clear();
for (final String s : DropFile.getConfig().getConfigurationSection("random-drops").getKeys(false)) {
final Drop d = new Drop(s);
RandomDropData.drops.add(d);
}
}
public static Drop getDropByName(final String name) {
for (final Drop d : RandomDropData.drops) {
if (d.getName().equalsIgnoreCase(name)) {
return d;
}
}
return null;
}
@Override
public void breakBlock(final Block block, final Player player, final ItemStack item) {
final List<ItemStack> drop = new ArrayList<ItemStack>();
for (final Drop d : RandomDropData.drops) {
final ItemStack itemDrop = d.getWhat().clone();
int expDrop = d.getExp();
if (!d.getFrom().equals((Object)block.getType())) {
continue;
}
if (!d.getTools().contains(item.getType())) {
continue;
}
if (!d.getBiomes().contains(block.getBiome())) {
continue;
}
final int y = block.getLocation().getBlockY();
if (y < d.getMinHeight()) {
continue;
}
if (y > d.getMaxHeight()) {
continue;
}
double chance = d.getChance();
if (player.hasPermission("core.drop.vip")) {
chance *= 0.25;
}
else if (player.hasPermission("core.drop.svip")) {
chance *= 0.5;
}
final User u = UserManager.getUser(player);
final Guild g = GuildManager.getGuild(player);
if (Config.TURBO_DROP > System.currentTimeMillis() || (u != null && u.getTurboDrop() > System.currentTimeMillis()) || (g != null && g.getTurboDrop() > System.currentTimeMillis())) {
chance *= 1.0;
}
double bonus = 0.0;
if (u != null) {
bonus = d.getChance() / 100.0 * (100.0 + u.getLvl() * 1.2) - d.getChance();
}
chance += bonus;
if (!RandomUtil.getChance(chance)) {
continue;
}
if (item.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS) && d.isFortune()) {
final int a = DropUtil.addFortuneEnchant((d.getMinAmount() == d.getMaxAmount()) ? d.getMinAmount() : RandomUtil.getRandInt(d.getMinAmount(), d.getMaxAmount()), item);
itemDrop.setAmount(a);
expDrop *= a;
}
if (!d.isDisabled(player.getUniqueId())) {
drop.add(itemDrop);
}
player.giveExp(expDrop);
if (u != null) {
u.setExp(u.getExp() + expDrop);
}
LevelUtil.checkLevel(u);
if (d.getMessage().equalsIgnoreCase("")) {
continue;
}
String msg = d.getMessage();
msg = msg.replace("{AMOUNT}", Integer.toString(itemDrop.getAmount()));
msg = msg.replace("{EXP}", String.valueOf(Integer.toString(expDrop)) + " &apkt." + (d.getDisabled().contains(player.getUniqueId()) ? " &8(&cNieaktywny&8)" : ""));
if (isNoMsg(player.getUniqueId())) {
continue;
}
ChatUtil.sendMessage((CommandSender)player, msg);
}
if (!RandomDropData.noCobble.contains(player.getUniqueId())) {
drop.add(new ItemStack(item.containsEnchantment(Enchantment.SILK_TOUCH) ? Material.STONE : Material.COBBLESTONE, 1));
}
DropUtil.addItemsToPlayer(player, drop, block);
DropUtil.recalculateDurability(player, item);
block.setType(Material.AIR);
}
@Override
public DropType getDropType() {
return DropType.RANDOM_DROP;
}
public static List<Drop> getDrops() {
return RandomDropData.drops;
}
}