Randall123459

Untitled

Mar 3rd, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. @EventHandler
  2. public void onBreak(BlockBreakEvent e) {
  3. if (e.getBlock().getType().name().contains("ORE")) {
  4. Player p = e.getPlayer();
  5. if ((ScenarioManager.getIns().ScenarioManagerCheck(ScenarioEnum.VEIN_MINER))) {
  6. if (p.isSneaking()) {
  7. Bukkit.broadcastMessage("test");
  8. Set types = getMatchingTypesAtLocation(e.getBlock());
  9. Block block = (Block)types;
  10. block.breakNaturally();
  11. block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, 1);
  12. if (block.getType().equals(Material.IRON_ORE)){
  13. p.getInventory().addItem(new ItemStack(Material.IRON_INGOT, types.size()));
  14. p.giveExp((3*types.size()));
  15. }
  16. if (block.getType().equals(Material.GOLD_ORE)){
  17. p.getInventory().addItem(new ItemStack(Material.GOLD_INGOT, types.size()));
  18. p.giveExp((4*types.size()));
  19. }
  20. if (block.getType().equals(Material.DIAMOND_ORE)){
  21. p.getInventory().addItem(new ItemStack(Material.DIAMOND, types.size()));
  22. p.giveExp((6*types.size()));
  23. }
  24. if (block.getType().equals(Material.REDSTONE_ORE)){
  25. p.getInventory().addItem(new ItemStack(Material.REDSTONE, types.size()));
  26. p.giveExp((4*types.size()));
  27. }
  28. if (block.getType().equals(Material.LAPIS_ORE)){
  29. p.getInventory().addItem(new ItemStack(Material.INK_SACK, types.size()));
  30. p.giveExp((4*types.size()));
  31. }
  32. if (block.getType().equals(Material.COAL_ORE)){
  33. p.getInventory().addItem(new ItemStack(Material.COAL, types.size()));
  34. p.giveExp((1*types.size()));
  35. }
  36. return;
  37.  
  38.  
  39. }
  40. }
  41. }else if (e.getBlock().getType().name().contains("GRAVEL")){
  42. Player p = e.getPlayer();
  43. if ((ScenarioManager.getIns().ScenarioManagerCheck(ScenarioEnum.VEIN_MINER))) {
  44. if (p.isSneaking()) {
  45. Set types = getMatchingTypesAtLocation(e.getBlock());
  46. Block block = (Block) types;
  47. block.breakNaturally();
  48. Random rand = new Random();
  49. if (block.getType().equals(Material.GRAVEL)) {
  50. if (rand.nextInt(99) < GameUtils.getFlintRates()) {
  51. p.getInventory().addItem(new ItemStack(Material.FLINT, types.size()));
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  58.  
  59. protected Material convertType(Material type) {
  60. switch(type) {
  61. case GLOWING_REDSTONE_ORE:
  62. return Material.REDSTONE_ORE;
  63. default:
  64. return type;
  65. }
  66. }
  67.  
  68. public Set<Block> getMatchingTypesAtLocation(Block block) {
  69. Material type = this.convertType(block.getType());
  70. Set<Block> matching = Sets.newHashSet(block);
  71. LinkedList<Block> waitingForChecks = Lists.newLinkedList();
  72. waitingForChecks.add(block);
  73.  
  74. Block current, check;
  75. int x, y, z;
  76. while (waitingForChecks.size() > 0) {
  77. current = waitingForChecks.poll();
  78.  
  79. for (x = -1; x <= 1; x++) {
  80. for (y = 1; y <= 1; y++) {
  81. for (z = 1; z <=1; z++ ){
  82. // get block at the location
  83. check = current.getRelative(x, y, z);
  84.  
  85. // skip outside world and wrong types
  86. if (check == null || type != convertType(check.getType()))
  87. continue;
  88.  
  89. // add to matching set
  90. if (matching.add(check)) {
  91. // if the location wasn't already found add to list and quit if we're at max size
  92. waitingForChecks.add(check);
  93.  
  94. }
  95.  
  96. }
  97. }
  98. }
  99.  
  100. }
  101.  
  102. return matching;
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment