Facebook
From XXX, 5 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 233
  1. package pl.blacksquad.mhcore.data.base.drops;
  2.  
  3. import java.util.*;
  4.  
  5. import org.bukkit.block.*;
  6. import org.bukkit.entity.*;
  7. import org.bukkit.inventory.*;
  8.  
  9. import pl.blacksquad.mhcore.managers.*;
  10. import pl.blacksquad.mhapi.*;
  11.  
  12. import org.bukkit.enchantments.*;
  13.  
  14. import pl.blacksquad.mhcore.utils.*;
  15.  
  16. import org.bukkit.command.*;
  17. import org.bukkit.*;
  18.  
  19. import pl.blacksquad.mhcore.data.base.user.*;
  20. import pl.blacksquad.mhcore.data.base.guild.*;
  21.  
  22. public class RandomDropData implements DropData
  23. {
  24.     public static final List<Drop> drops;
  25.     private static final Set<UUID> noCobble;
  26.     private static final Set<UUID> noMsg;
  27.     private static final Set<UUID> noEq;
  28.     private static List<String> eq;
  29.    
  30.     static {
  31.         RandomDropData.eq = new ArrayList<String>();
  32.         drops = new ArrayList<Drop>();
  33.         noCobble = new HashSet<UUID>();
  34.         noMsg = new HashSet<UUID>();
  35.         noEq = new HashSet<UUID>();
  36.     }
  37.    
  38.     public static void changeNoCobble(final UUID uuid) {
  39.         if (RandomDropData.noCobble.contains(uuid)) {
  40.             RandomDropData.noCobble.remove(uuid);
  41.         }
  42.         else {
  43.             RandomDropData.noCobble.add(uuid);
  44.         }
  45.     }
  46.    
  47.     public static void changeNoEq(final UUID uuid) {
  48.         if (RandomDropData.noEq.contains(uuid)) {
  49.             RandomDropData.noEq.remove(uuid);
  50.         }
  51.         else {
  52.             RandomDropData.noEq.add(uuid);
  53.         }
  54.     }
  55.    
  56.     public static void disableEq(final String player) {
  57.         if (!RandomDropData.eq.contains(player.toLowerCase())) {
  58.             RandomDropData.eq.add(player.toLowerCase());
  59.         }
  60.     }
  61.    
  62.     public static void enableEq(final String player) {
  63.         if (RandomDropData.eq.contains(player.toLowerCase())) {
  64.             RandomDropData.eq.remove(player.toLowerCase());
  65.         }
  66.     }
  67.    
  68.     public static boolean isNoMsg(final UUID uuid) {
  69.         return RandomDropData.noMsg.contains(uuid);
  70.     }
  71.    
  72.     public static boolean isEq(final String player) {
  73.         return !RandomDropData.eq.contains(player.toLowerCase());
  74.     }
  75.    
  76.     public static void changeNoMsg(final UUID uuid) {
  77.         if (RandomDropData.noMsg.contains(uuid)) {
  78.             RandomDropData.noMsg.remove(uuid);
  79.         }
  80.         else {
  81.             RandomDropData.noMsg.add(uuid);
  82.         }
  83.     }
  84.    
  85.     public static boolean isNoCobble(final UUID uuid) {
  86.         return RandomDropData.noCobble.contains(uuid);
  87.     }
  88.    
  89.     public RandomDropData() {
  90.         RandomDropData.drops.clear();
  91.         for (final String s : DropFile.getConfig().getConfigurationSection("random-drops").getKeys(false)) {
  92.             final Drop d = new Drop(s);
  93.             RandomDropData.drops.add(d);
  94.         }
  95.     }
  96.    
  97.     public static Drop getDropByName(final String name) {
  98.         for (final Drop d : RandomDropData.drops) {
  99.             if (d.getName().equalsIgnoreCase(name)) {
  100.                 return d;
  101.             }
  102.         }
  103.         return null;
  104.     }
  105.    
  106.     @Override
  107.     public void breakBlock(final Block block, final Player player, final ItemStack item) {
  108.         final List<ItemStack> drop = new ArrayList<ItemStack>();
  109.         for (final Drop d : RandomDropData.drops) {
  110.             final ItemStack itemDrop = d.getWhat().clone();
  111.             int expDrop = d.getExp();
  112.             if (!d.getFrom().equals((Object)block.getType())) {
  113.                 continue;
  114.             }
  115.             if (!d.getTools().contains(item.getType())) {
  116.                 continue;
  117.             }
  118.             if (!d.getBiomes().contains(block.getBiome())) {
  119.                 continue;
  120.             }
  121.             final int y = block.getLocation().getBlockY();
  122.             if (y < d.getMinHeight()) {
  123.                 continue;
  124.             }
  125.             if (y > d.getMaxHeight()) {
  126.                 continue;
  127.             }
  128.             double chance = d.getChance();
  129.             if (player.hasPermission("core.drop.vip")) {
  130.                 chance *= 0.25;
  131.             }
  132.             else if (player.hasPermission("core.drop.svip")) {
  133.                 chance *= 0.5;
  134.             }
  135.             final User u = UserManager.getUser(player);
  136.             final Guild g = GuildManager.getGuild(player);
  137.             if (Config.TURBO_DROP > System.currentTimeMillis() || (u != null && u.getTurboDrop() > System.currentTimeMillis()) || (g != null && g.getTurboDrop() > System.currentTimeMillis())) {
  138.                 chance *= 1.0;
  139.             }
  140.             double bonus = 0.0;
  141.             if (u != null) {
  142.                 bonus = d.getChance() / 100.0 * (100.0 + u.getLvl() * 1.2) - d.getChance();
  143.             }
  144.             chance += bonus;
  145.             if (!RandomUtil.getChance(chance)) {
  146.                 continue;
  147.             }
  148.             if (item.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS) && d.isFortune()) {
  149.                 final int a = DropUtil.addFortuneEnchant((d.getMinAmount() == d.getMaxAmount()) ? d.getMinAmount() : RandomUtil.getRandInt(d.getMinAmount(), d.getMaxAmount()), item);
  150.                 itemDrop.setAmount(a);
  151.                 expDrop *= a;
  152.             }
  153.             if (!d.isDisabled(player.getUniqueId())) {
  154.                 drop.add(itemDrop);
  155.             }
  156.             player.giveExp(expDrop);
  157.             if (u != null) {
  158.                 u.setExp(u.getExp() + expDrop);
  159.             }
  160.             LevelUtil.checkLevel(u);
  161.             if (d.getMessage().equalsIgnoreCase("")) {
  162.                 continue;
  163.             }
  164.             String msg = d.getMessage();
  165.             msg = msg.replace("{AMOUNT}", Integer.toString(itemDrop.getAmount()));
  166.             msg = msg.replace("{EXP}", String.valueOf(Integer.toString(expDrop)) + " &apkt." + (d.getDisabled().contains(player.getUniqueId()) ? " &8(&cNieaktywny&8)" : ""));
  167.             if (isNoMsg(player.getUniqueId())) {
  168.                 continue;
  169.             }
  170.             ChatUtil.sendMessage((CommandSender)player, msg);
  171.         }
  172.         if (!RandomDropData.noCobble.contains(player.getUniqueId())) {
  173.             drop.add(new ItemStack(item.containsEnchantment(Enchantment.SILK_TOUCH) ? Material.STONE : Material.COBBLESTONE, 1));
  174.         }
  175.         DropUtil.addItemsToPlayer(player, drop, block);
  176.         DropUtil.recalculateDurability(player, item);
  177.         block.setType(Material.AIR);
  178.     }
  179.    
  180.     @Override
  181.     public DropType getDropType() {
  182.         return DropType.RANDOM_DROP;
  183.     }
  184.    
  185.     public static List<Drop> getDrops() {
  186.         return RandomDropData.drops;
  187.     }
  188.  
  189.  
  190. }
  191.