Plugin not working

Discussion in 'Plugin Development' started by chasertw123, Jan 15, 2014.

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

    chasertw123

    Hi I made the plugin below but from some reason it isn't working. I get no error messages but when I mine a block it just does it the normal way. Here is my code:

    Code:java
    1. package me.chasertw123.FortuneMultiplier;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.enchantments.Enchantment;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.BlockBreakEvent;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class FortuneMultiplier extends JavaPlugin implements Listener {
    16.  
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18. public static FortuneMultiplier plugin;
    19.  
    20. @Override
    21. public void onDisable() {
    22. PluginDescriptionFile pdfFile = this.getDescription();
    23. this.logger.info("[FortuneMultiplier]"+ "Version " + pdfFile.getVersion() + " Has Been Disabled!");
    24. saveConfig();
    25. }
    26.  
    27. @Override
    28. public void onEnable() {
    29. PluginDescriptionFile pdfFile = this.getDescription();
    30. this.logger.info("[FortuneMultiplier]"+ "Version " + pdfFile.getVersion() + " Has Been Enabled!");
    31. getConfig().options().copyDefaults(true);
    32. saveConfig();
    33. }
    34.  
    35. @EventHandler
    36. public void onBlockBreakEvent (BlockBreakEvent e) {
    37.  
    38. Player player = (Player) e.getPlayer();
    39. Material b = e.getBlock().getType();
    40. Material p = player.getItemInHand().getType();
    41. Location loc = e.getBlock().getLocation();
    42. int loot = player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
    43.  
    44. if (player.hasPermission("fm.use")) {
    45. if (player.getItemInHand().containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) {
    46. if (b == Material.COAL_ORE) {
    47. if (p == Material.WOOD_PICKAXE || p == Material.STONE_PICKAXE || p == Material.IRON_PICKAXE ||
    48. p == Material.GOLD_PICKAXE || p == Material.DIAMOND_PICKAXE) {
    49. int amt = plugin.getConfig().getInt("Fortune."+loot);
    50. e.setCancelled(true);
    51. e.getBlock().setType(Material.AIR);
    52. e.getPlayer().getWorld().dropItemNaturally(loc, new ItemStack(Material.COAL, amt));
    53. }
    54. } if (b == Material.IRON_ORE) {
    55. if (p == Material.STONE_PICKAXE || p == Material.IRON_PICKAXE || p == Material.GOLD_PICKAXE
    56. || p == Material.DIAMOND_PICKAXE) {
    57. int amt = plugin.getConfig().getInt("Fortune."+loot);
    58. e.setCancelled(true);
    59. e.getBlock().setType(Material.AIR);
    60. e.getPlayer().getWorld().dropItemNaturally(loc, new ItemStack(Material.IRON_INGOT, amt));
    61. }
    62. } if (b == Material.GOLD_ORE) {
    63. if (p == Material.IRON_PICKAXE || p == Material.GOLD_PICKAXE || p ==
    64. Material.DIAMOND_PICKAXE) {
    65. int amt = plugin.getConfig().getInt("Fortune."+loot);
    66. e.setCancelled(true);
    67. e.getBlock().setType(Material.AIR);
    68. e.getPlayer().getWorld().dropItemNaturally(loc, new ItemStack(Material.GOLD_INGOT, amt));
    69. }
    70. } if (b == Material.DIAMOND_ORE) {
    71. if (p == Material.IRON_PICKAXE || p == Material.GOLD_PICKAXE || p ==
    72. Material.DIAMOND_PICKAXE) {
    73. int amt = plugin.getConfig().getInt("Fortune."+loot);
    74. e.setCancelled(true);
    75. e.getBlock().setType(Material.AIR);
    76. e.getPlayer().getWorld().dropItemNaturally(loc, new ItemStack(Material.DIAMOND, amt));
    77. }
    78. } if (b == Material.EMERALD_ORE) {
    79. if (p == Material.IRON_PICKAXE || p == Material.GOLD_PICKAXE || p ==
    80. Material.DIAMOND_PICKAXE) {
    81. int amt = plugin.getConfig().getInt("Fortune."+loot);
    82. e.setCancelled(true);
    83. e.getBlock().setType(Material.AIR);
    84. e.getPlayer().getWorld().dropItemNaturally(loc, new ItemStack(Material.EMERALD, amt));
    85. }
    86. } if (b == Material.LAPIS_ORE) {
    87. if (p == Material.IRON_PICKAXE || p == Material.GOLD_PICKAXE || p ==
    88. Material.DIAMOND_PICKAXE) {
    89. int amt = plugin.getConfig().getInt("Fortune."+loot);
    90. e.setCancelled(true);
    91. e.getBlock().setType(Material.AIR);
    92. e.getPlayer().getWorld().dropItemNaturally(loc, new ItemStack(Material.INK_SACK, amt*3,
    93. (short)4));
    94. }
    95. } if (b == Material.GLOWING_REDSTONE_ORE || b == Material.REDSTONE_ORE) {
    96. if (p == Material.IRON_PICKAXE || p == Material.GOLD_PICKAXE || p ==
    97. Material.DIAMOND_PICKAXE) {
    98. int amt = plugin.getConfig().getInt("Fortune."+loot);
    99. e.setCancelled(true);
    100. e.getBlock().setType(Material.AIR);
    101. e.getPlayer().getWorld().dropItemNaturally(loc, new ItemStack(Material.REDSTONE, amt*2));
    102. }
    103. }
    104. }
    105. }
    106. }
    107. }


    Also here is the config.yml

    Code:
    # FortuneMultiplier Configuration
     
    Fortune:
    1: 1
    2: 1
    3: 2
    4: 2
    5: 2
    6: 2
    7: 2
    8: 2
    9: 2
    10: 3
    11: 3
    12: 3
    13: 3
    14: 3
    15: 3
    16: 3
    17: 3
    18: 3
    19: 3
    20: 4
    21: 4
    22: 4
    23: 4
    24: 4
    25: 4
    26: 4
    27: 4
    28: 4
    29: 4
    30: 5
    31: 5
    32: 5
    33: 5
    34: 5
    35: 5
    36: 5
    37: 5
    38: 5
    39: 5
    40: 6
    41: 6
    42: 6
    43: 6
    44: 6
    45: 6
    46: 6
    47: 6
    48: 6
    49: 6
    50: 8
    51: 8
    52: 8
    53: 8
    54: 8
    55: 8
    56: 8
    57: 8
    58: 8
    59: 8
    60: 9
    61: 9
    62: 9
    63: 9
    64: 9
    65: 9
    66: 9
    67: 9
    68: 9
    69: 9
    70: 12
    71: 12
    72: 12
    73: 12
    74: 12
    75: 12
    76: 12
    77: 12
    78: 12
    79: 12
    80: 18
    81: 18
    82: 18
    83: 18
    84: 18
    85: 18
    86: 18
    87: 18
    88: 18
    89: 18
    90: 25
     
  2. Offline

    Regagames

    Does the plugin enable?
     
  3. Offline

    chasertw123

    Yes the plugin does enable and the config does generate. I test it in the game and normal stuff just happens.
     
  4. Offline

    Regagames

    @chastertw123 Ok, we are one step farther than
     
  5. Offline

    chasertw123

    Anyone possibly know what I am doing wrong?

    I really need someone to tell me what I am doing wrong. I can'r figure it out!

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

    xTrollxDudex

  7. Offline

    AmShaegar

    Exactly. Sounds weired but you need to register your main class if it's a listener. Looks like this in onEnable:
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
     
  8. Offline

    chasertw123

    Ya I forgot to do that. Thanks guys!
     
Thread Status:
Not open for further replies.

Share This Page