Advertisement
Guest User

Untitled

a guest
Jan 14th, 2020
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. public class BlockBreak
  2. implements Listener
  3. {
  4. private MinePickup plugin;
  5.  
  6. public BlockBreak(MinePickup plugin)
  7. {
  8. this.plugin = plugin;
  9. }
  10.  
  11. public boolean isCrop(Material mat) {
  12. return (mat == Material.POTATO) || (mat == Material.CARROT) || (mat == Material.WHEAT) || (mat == Material.COCOA) || (mat == Material.NETHER_WART);
  13. }
  14.  
  15. @EventHandler
  16. public void onBlockBreak(BlockBreakEvent event) {
  17. Player player = event.getPlayer();
  18. Block blk = event.getBlock();
  19.  
  20. if (!WorldGuardHook.canBuild(player, blk.getLocation()))
  21. return;
  22. double num;
  23. double num;
  24. if (this.plugin.getBlocks().containsKey(player.getUniqueId())) {
  25. this.plugin.getBlocks().put(player.getUniqueId(), Double.valueOf(((Double)this.plugin.getBlocks().get(player.getUniqueId())).doubleValue() + 1.0D));
  26. num = ((Double)this.plugin.getBlocks().get(player.getUniqueId())).doubleValue();
  27. }
  28. else {
  29. this.plugin.getBlocks().put(player.getUniqueId(), Double.valueOf(1.0D));
  30. num = 1.0D;
  31. }
  32. String msg = ChatColor.AQUA + ChatColor.BOLD + "You have mined a total of " + ChatColor.GOLD + ChatColor.BOLD + num + " blocks!";
  33. msg = msg.replace(".0", "");
  34. ActionBar.sendActionBar(player, msg);
  35. event.setCancelled(true);
  36. if (player.getItemInHand() != null)
  37. if (player.getInventory().firstEmpty() == -1) {
  38. final Hologram hologram = HologramsAPI.createHologram(this.plugin, new Location(blk.getLocation().getWorld(), blk.getLocation().getX(), blk.getLocation().getY() + 2.0D, blk.getLocation().getZ()));
  39. hologram.appendTextLine(ChatColor.BOLD + ChatColor.YELLOW + "Inventory Full!");
  40. Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable()
  41. {
  42. public void run() {
  43. hologram.delete();
  44. }
  45. }
  46. , 40L);
  47. }
  48. else if (player.getWorld().getName().equalsIgnoreCase("plotworld"))
  49. {
  50. int r;
  51. ItemStack item;
  52. if (isCrop(blk.getType())) {
  53. r = this.plugin.getRandom().nextInt(4) + 1;
  54. if (blk.getType() == Material.COCOA) {
  55. if (blk.getData() != 11) {
  56. r = 1;
  57. }
  58. item = new ItemStack(Material.COCOA_BEANS, r, (short)3);
  59. player.getInventory().addItem(new ItemStack[] { item });
  60. }
  61.  
  62. for (ItemStack is : blk.getDrops()) {
  63. if (is.getType() == Material.WHEAT) {
  64. ItemStack seeds = new ItemStack(Material.WHEAT_SEEDS);
  65. seeds.setAmount(r);
  66. is.setAmount(r);
  67. player.getInventory().addItem(new ItemStack[] { seeds });
  68. player.getInventory().addItem(new ItemStack[] { is });
  69. }
  70. else {
  71. is.setAmount(r);
  72. player.getInventory().addItem(new ItemStack[] { is });
  73. }
  74. }
  75. }
  76. for (ItemStack is2 : blk.getDrops()) {
  77. player.getInventory().addItem(new ItemStack[] { is2 });
  78. }
  79. blk.setType(Material.AIR);
  80. }
  81. else if ((WorldGuardHook.canBuild(player, blk.getLocation())) || (player.isOp()))
  82. {
  83. int r2;
  84. ItemStack item2;
  85. if (isCrop(blk.getType())) {
  86. r2 = this.plugin.getRandom().nextInt(4) + 1;
  87. if (blk.getType() == Material.COCOA) {
  88. if (blk.getData() != 11) {
  89. r2 = 1;
  90. }
  91. item2 = new ItemStack(Material.COCOA_BEANS, r2, (short)3);
  92. player.getInventory().addItem(new ItemStack[] { item2 });
  93. }
  94.  
  95. for (ItemStack is2 : blk.getDrops())
  96. if (is2.getType() == Material.WHEAT) {
  97. ItemStack seeds2 = new ItemStack(Material.WHEAT_SEEDS);
  98. seeds2.setAmount(r2);
  99. is2.setAmount(r2);
  100. player.getInventory().addItem(new ItemStack[] { seeds2 });
  101. player.getInventory().addItem(new ItemStack[] { is2 });
  102. }
  103. else {
  104. is2.setAmount(r2);
  105. player.getInventory().addItem(new ItemStack[] { is2 });
  106. }
  107. }
  108. else
  109. {
  110. for (ItemStack is3 : blk.getDrops()) {
  111. player.getInventory().addItem(new ItemStack[] { is3 });
  112. }
  113. }
  114. blk.setType(Material.AIR);
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement