Cant Pick Up Items?

Discussion in 'Plugin Development' started by Kassestral, Jun 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Kassestral

    If the pickaxe does not have the enchant fortune.{10,15,20,30,40,50,60,90} then it drops a single entity which cannot be picked up, any help?
    Code:java
    1.  
    2. @EventHandler
    3. public void onBrokeBlock(BlockBreakEvent e){
    4. //Main Variables
    5. Player p = e.getPlayer();
    6. int enchant = p.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
    7. Block block = e.getBlock();
    8. Location location = block.getLocation();
    9.  
    10. //ItemStacks Blocks
    11. ItemStack netherrack = new ItemStack(Material.NETHERRACK, calculateDrops(enchant));
    12. ItemStack coalblock = new ItemStack(Material.COAL_BLOCK, calculateDrops(enchant));
    13. ItemStack obsidian = new ItemStack(Material.OBSIDIAN, calculateDrops(enchant));
    14. ItemStack ironblock = new ItemStack(Material.IRON_BLOCK, calculateDrops(enchant));
    15. ItemStack goldblock = new ItemStack(Material.GOLD_BLOCK, calculateDrops(enchant));
    16. ItemStack redstoneblock = new ItemStack(Material.REDSTONE_BLOCK, calculateDrops(enchant));
    17. ItemStack diamondblock = new ItemStack(Material.DIAMOND_BLOCK, calculateDrops(enchant));
    18. ItemStack emeraldblock = new ItemStack(Material.EMERALD_BLOCK, calculateDrops(enchant));
    19.  
    20. //ItemStacks Ores
    21. ItemStack coalore = new ItemStack(Material.COAL, calculateDrops(enchant));
    22. ItemStack ironore = new ItemStack(Material.IRON_ORE, calculateDrops(enchant));
    23. ItemStack goldore = new ItemStack(Material.GOLD_ORE, calculateDrops(enchant));
    24. ItemStack redstoneore = new ItemStack(Material.REDSTONE, calculateDrops(enchant));
    25. ItemStack diamondore = new ItemStack(Material.DIAMOND, calculateDrops(enchant));
    26. ItemStack emeraldore = new ItemStack(Material.EMERALD, calculateDrops(enchant));
    27.  
    28.  
    29. if(block.getType().equals(Material.NETHERRACK)){
    30. e.setCancelled(true);
    31. changeBlock(block);
    32. block.getWorld().dropItemNaturally(location, netherrack);
    33. }
    34. if(block.getType().equals(Material.OBSIDIAN)){
    35. e.setCancelled(true);
    36. changeBlock(block);
    37. block.getWorld().dropItemNaturally(location, obsidian);
    38. }
    39. if(block.getType().equals(Material.COAL_ORE)){
    40. e.setCancelled(true);
    41. changeBlock(block);
    42. block.getWorld().dropItemNaturally(location, coalore);
    43. }
    44. if(block.getType().equals(Material.COAL_BLOCK)){
    45. e.setCancelled(true);
    46. changeBlock(block);
    47. block.getWorld().dropItemNaturally(location, coalblock);
    48. p.sendMessage("You got " + calculateDrops(enchant));
    49. }
    50. if(block.getType().equals(Material.IRON_BLOCK)){
    51. e.setCancelled(true);
    52. changeBlock(block);
    53. block.getWorld().dropItemNaturally(location, ironblock);
    54. }
    55. if(block.getType().equals(Material.GOLD_BLOCK)){
    56. e.setCancelled(true);
    57. changeBlock(block);
    58. block.getWorld().dropItemNaturally(location, goldblock);
    59. }
    60. if(block.getType().equals(Material.REDSTONE_BLOCK)){
    61. e.setCancelled(true);
    62. changeBlock(block);
    63. block.getWorld().dropItemNaturally(location, redstoneblock);
    64. }
    65. if(block.getType().equals(Material.DIAMOND_BLOCK)){
    66. e.setCancelled(true);
    67. changeBlock(block);
    68. block.getWorld().dropItemNaturally(location, diamondblock);
    69. }
    70. if(block.getType().equals(Material.EMERALD_BLOCK)){
    71. e.setCancelled(true);
    72. changeBlock(block);
    73. block.getWorld().dropItemNaturally(location, emeraldblock);
    74. }
    75. if(block.getType().equals(Material.IRON_ORE)){
    76. e.setCancelled(true);
    77. changeBlock(block);
    78. block.getWorld().dropItemNaturally(location, ironore);
    79. }
    80. if(block.getType().equals(Material.GOLD_ORE)){
    81. e.setCancelled(true);
    82. changeBlock(block);
    83. block.getWorld().dropItemNaturally(location, goldore);
    84. }
    85. if(block.getType().equals(Material.REDSTONE_ORE)){
    86. e.setCancelled(true);
    87. changeBlock(block);
    88. block.getWorld().dropItemNaturally(location, redstoneore);
    89. }
    90. if(block.getType().equals(Material.DIAMOND_ORE)){
    91. e.setCancelled(true);
    92. changeBlock(block);
    93. block.getWorld().dropItemNaturally(location, diamondore);
    94. }
    95. if(block.getType().equals(Material.EMERALD_ORE)){
    96. e.setCancelled(true);
    97. changeBlock(block);
    98. block.getWorld().dropItemNaturally(location, emeraldore);
    99. }
    100. }
    101.  
    102. public void changeBlock(Block block){
    103. block.setType(Material.AIR);
    104. }
    105.  
    106. public int calculateDrops(int enchant){
    107. int amount = 1;
    108.  
    109. if(enchant == 10){
    110. amount = +1;
    111. }
    112. if(enchant == 15){
    113. amount = +1;
    114. }
    115. if(enchant == 20){
    116. amount = +2;
    117. }
    118. if(enchant == 30){
    119. amount = +5;
    120. }
    121. if(enchant == 40){
    122. amount = +6;
    123. }
    124. if(enchant == 50){
    125. amount = +8;
    126. }
    127. if(enchant == 60){
    128. amount = +10;
    129. }
    130. if(enchant == 90){
    131. amount = +14;
    132. }
    133. else{
    134. amount = +0;
    135. }
    136. return amount;
    137. }


    timtower

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  2. Offline

    timtower Administrator Administrator Moderator

    Tried debugging the value that you get?
     
  3. Offline

    Kassestral

    timtower
    Code:java
    1.  
    2.  
    3. public class Main extends JavaPlugin implements Listener{
    4.  
    5. public void onEnable(){
    6. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    7. }
    8.  
    9. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    10. Player p = (Player) sender;
    11. if(cmd.getName().equalsIgnoreCase("giveall") && p.hasPermission("prison.command.giveall")){
    12. ItemStack item = p.getItemInHand();
    13.  
    14. Player[] onlinePlayers = p.getServer().getOnlinePlayers();
    15. for (Player player : onlinePlayers){
    16. player.sendMessage(ChatColor.GREEN + "You have been given an item, compliments of " + ChatColor.AQUA + p.getName());
    17. player.getInventory().addItem(item);
    18. }
    19. }
    20. return true;
    21. }
    22.  
    23. @EventHandler
    24. public void onBrokeBlock(BlockBreakEvent e){
    25. //Main Variables
    26. Player p = e.getPlayer();
    27. int enchant = p.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
    28. Block block = e.getBlock();
    29. Location location = block.getLocation();
    30.  
    31. //ItemStacks Blocks
    32. ItemStack netherrack = new ItemStack(Material.NETHERRACK, calculateDrops(enchant));
    33. ItemStack coalblock = new ItemStack(Material.COAL_BLOCK, calculateDrops(enchant));
    34. ItemStack obsidian = new ItemStack(Material.OBSIDIAN, calculateDrops(enchant));
    35. ItemStack ironblock = new ItemStack(Material.IRON_BLOCK, calculateDrops(enchant));
    36. ItemStack goldblock = new ItemStack(Material.GOLD_BLOCK, calculateDrops(enchant));
    37. ItemStack redstoneblock = new ItemStack(Material.REDSTONE_BLOCK, calculateDrops(enchant));
    38. ItemStack diamondblock = new ItemStack(Material.DIAMOND_BLOCK, calculateDrops(enchant));
    39. ItemStack emeraldblock = new ItemStack(Material.EMERALD_BLOCK, calculateDrops(enchant));
    40.  
    41. //ItemStacks Ores
    42. ItemStack coalore = new ItemStack(Material.COAL, calculateDrops(enchant));
    43. ItemStack ironore = new ItemStack(Material.IRON_ORE, calculateDrops(enchant));
    44. ItemStack goldore = new ItemStack(Material.GOLD_ORE, calculateDrops(enchant));
    45. ItemStack redstoneore = new ItemStack(Material.REDSTONE, calculateDrops(enchant));
    46. ItemStack diamondore = new ItemStack(Material.DIAMOND, calculateDrops(enchant));
    47. ItemStack emeraldore = new ItemStack(Material.EMERALD, calculateDrops(enchant));
    48.  
    49. p.sendMessage("Debug: " + enchant);
    50. if(block.getType().equals(Material.NETHERRACK)){
    51. e.setCancelled(true);
    52. changeBlock(block);
    53. block.getWorld().dropItemNaturally(location, netherrack);
    54. }
    55. if(block.getType().equals(Material.OBSIDIAN)){
    56. e.setCancelled(true);
    57. changeBlock(block);
    58. block.getWorld().dropItemNaturally(location, obsidian);
    59. }
    60. if(block.getType().equals(Material.COAL_ORE)){
    61. e.setCancelled(true);
    62. changeBlock(block);
    63. block.getWorld().dropItemNaturally(location, coalore);
    64. }
    65. if(block.getType().equals(Material.COAL_BLOCK)){
    66. e.setCancelled(true);
    67. p.sendMessage("Debug: " + enchant);
    68. changeBlock(block);
    69. block.getWorld().dropItemNaturally(location, coalblock);
    70. }
    71. if(block.getType().equals(Material.IRON_BLOCK)){
    72. e.setCancelled(true);
    73. changeBlock(block);
    74. block.getWorld().dropItemNaturally(location, ironblock);
    75. }
    76. if(block.getType().equals(Material.GOLD_BLOCK)){
    77. e.setCancelled(true);
    78. changeBlock(block);
    79. block.getWorld().dropItemNaturally(location, goldblock);
    80. }
    81. if(block.getType().equals(Material.REDSTONE_BLOCK)){
    82. e.setCancelled(true);
    83. changeBlock(block);
    84. block.getWorld().dropItemNaturally(location, redstoneblock);
    85. }
    86. if(block.getType().equals(Material.DIAMOND_BLOCK)){
    87. e.setCancelled(true);
    88. changeBlock(block);
    89. block.getWorld().dropItemNaturally(location, diamondblock);
    90. }
    91. if(block.getType().equals(Material.EMERALD_BLOCK)){
    92. e.setCancelled(true);
    93. changeBlock(block);
    94. block.getWorld().dropItemNaturally(location, emeraldblock);
    95. }
    96. if(block.getType().equals(Material.IRON_ORE)){
    97. e.setCancelled(true);
    98. changeBlock(block);
    99. block.getWorld().dropItemNaturally(location, ironore);
    100. }
    101. if(block.getType().equals(Material.GOLD_ORE)){
    102. e.setCancelled(true);
    103. changeBlock(block);
    104. block.getWorld().dropItemNaturally(location, goldore);
    105. }
    106. if(block.getType().equals(Material.REDSTONE_ORE)){
    107. e.setCancelled(true);
    108. changeBlock(block);
    109. block.getWorld().dropItemNaturally(location, redstoneore);
    110. }
    111. if(block.getType().equals(Material.DIAMOND_ORE)){
    112. e.setCancelled(true);
    113. changeBlock(block);
    114. block.getWorld().dropItemNaturally(location, diamondore);
    115. }
    116. if(block.getType().equals(Material.EMERALD_ORE)){
    117. e.setCancelled(true);
    118. changeBlock(block);
    119. block.getWorld().dropItemNaturally(location, emeraldore);
    120. }
    121. }
    122. }


    added two debug messages but it doesnt seem to be registering the event?
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    Kilovice

    Kassestral
    Best thing that I can suggest is to put them in different classes and register the events and commands from the main class
     
  6. Offline

    Garris0n

    The plugin is enabling properly, correct? No exceptions/errors anywhere?
     
  7. Offline

    Kassestral

    Garris0n Kilovice timtower
    Plugin is enabling properly, also I did a debug and it outputs the enchantment on an unenchanted pickaxe as 0, so I added that to the method just incase, but it seems that people cant pick up item stacks below 3 items
     
Thread Status:
Not open for further replies.

Share This Page