Plugin not doing what it should

Discussion in 'Plugin Development' started by C0lA_K1nG, Jun 13, 2014.

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

    C0lA_K1nG

    Hello there,
    I have created a plugin (Emerald Effects) and the plugin has no errors in the console but it is not doing the EventHandler but it is doing the Commands

    Code:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if(p.hasPermission("emeraldeffects.use")) {
    5. if ((p.getItemInHand().getType() == Material.getMaterial(getConfig().getString("ID"))) && (e.getAction() != Action.RIGHT_CLICK_AIR)) {
    6. p.getInventory().removeItem(new ItemStack(Material.getMaterial(getConfig().getString("ID")), 1));
    7. if (getConfig().getBoolean("Absorption") == true) {
    8. p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, getConfig().getInt("Absorption Time"), 1));
    9. }
    10. if (getConfig().getBoolean("Blindness") == true) {
    11. p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, getConfig().getInt("Blindness Time"), 1));
    12. }
    13. if (getConfig().getBoolean("Confusion") == true) {
    14. p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, getConfig().getInt("Confusion Time"), 1));
    15. }
    16. if (getConfig().getBoolean("Damage_Resistance") == true) {
    17. p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, getConfig().getInt("Damage_Resistance Time"), 1));
    18. }
    19. if (getConfig().getBoolean("Fast_Digging") == true) {
    20. p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, getConfig().getInt("Fast_Digging Time"), 1));
    21. }
    22. if (getConfig().getBoolean("Fire_Resistance") == true) {
    23. p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, getConfig().getInt("Fire_Resistance Time"), 1));
    24. }
    25. if (getConfig().getBoolean("Harm") == true) {
    26. p.addPotionEffect(new PotionEffect(PotionEffectType.HARM, getConfig().getInt("Harm Time"), 1));
    27. }
    28. if (getConfig().getBoolean("Health_Boost") == true) {
    29. p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, getConfig().getInt("Health_Boost Time"), 1));
    30. }
    31. if (getConfig().getBoolean("Hunger") == true) {
    32. p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, getConfig().getInt("Hunger Time"), 1));
    33. }
    34. if (getConfig().getBoolean("Increase_Damage") == true) {
    35. p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, getConfig().getInt("Increase_Damage Time"), 1));
    36. }
    37. if (getConfig().getBoolean("Invisibility") == true) {
    38. p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, getConfig().getInt("Invisibility Time"), 1));
    39. }
    40. if (getConfig().getBoolean("Jump") == true) {
    41. p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, getConfig().getInt("Jump Time"), 1));
    42. }
    43. if (getConfig().getBoolean("Night_Vision") == true) {
    44. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, getConfig().getInt("Night_Vision Time"), 1));
    45. }
    46. if (getConfig().getBoolean("Poison") == true) {
    47. p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, getConfig().getInt("Poison Time"), 1));
    48. }
    49. if (getConfig().getBoolean("Regeneration") == true) {
    50. p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, getConfig().getInt("Regeneration Time"), 1));
    51. }
    52. if (getConfig().getBoolean("Saturation") == true) {
    53. p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, getConfig().getInt("Saturation Time"), 1));
    54. }
    55. if (getConfig().getBoolean("Slow") == true) {
    56. p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, getConfig().getInt("Slow Time"), 1));
    57. }
    58. if (getConfig().getBoolean("Slow_Digging") == true) {
    59. p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, getConfig().getInt("Slow_Digging Time"), 1));
    60. }
    61. if (getConfig().getBoolean("Speed") == true) {
    62. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, getConfig().getInt("Speed Time"), 1));
    63. }
    64. if (getConfig().getBoolean("Water_Breathing") == true) {
    65. p.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, getConfig().getInt("Water_Breathing Time"), 1));
    66. }
    67. if (getConfig().getBoolean("Weakness") == true) {
    68. p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, getConfig().getInt("Weakness Time"), 1));
    69. }
    70. if (getConfig().getBoolean("Wither") == true) {
    71. p.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, getConfig().getInt("Wither Time"), 1));
    72. }
    73. }
    74. }
    75. }
    76.  
    77. @Override
    78. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    79. Player player = (Player) sender;
    80. if(player.hasPermission("emeraldeffects.admin")) {
    81. if (cmd.getName().equalsIgnoreCase("emeraldeffects") || cmd.getName().equalsIgnoreCase("ee")) {
    82. reloadConfig();
    83. sender.sendMessage(ChatColor.GREEN + "Configuration has been reloaded.");
    84. return true;
    85. } else if (cmd.getName().equalsIgnoreCase("emeraldeffects") || cmd.getName().equalsIgnoreCase("ee")) {
    86. if (!(sender instanceof Player)) {
    87. reloadConfig();
    88. sender.sendMessage(ChatColor.GREEN + "Configuration has been reloaded.");
    89. } else {
    90. sender.sendMessage(ChatColor.RED + "Error: You do not have permission.");
    91. }
    92. return true;
    93. }
    94. return false;
    95. }
    96. return false;
    97. }
    98. }
     
  2. Offline

    LordVakar

    C0lA_K1nG
    Is the String ID an actual item ID?
    Because Materials use names like GOLD_ORE
     
  3. Offline

    C0lA_K1nG

    Yes it's an ItemID. Is there a way to make it read the itemid?
     
  4. Offline

    Garris0n

    Yes, there is a getMaterial() method that accepts an integer. You're giving it a String.

    What you should really do is put the actual material in the config, but whatever.

    Also, what was wrong with using a loop instead of that ridiculous line of if statements?
     
  5. Offline

    Konkz

    Also, you don't have to check with "== true" but you can just do

    if(myBoolean) {
    //if it's true
    } else if (!anotherBoolean) {
    //if anotherBoolean is false
    }
     
    Garris0n likes this.
  6. Offline

    iTornado1234

    I don't know what other people think about this, but try using switch and cases.
     
  7. Offline

    Garris0n

    He should be using a loop.
     
  8. Offline

    pookeythekid

    Are you you registering the events correctly in your main class? And even if you are using your main class for this listener, you still have to register events from the class to itself, with something like this:
    Code:java
    1. PluginManager pm = getServer().getPluginManager();
    2.  
    3. pm.registerEvents(this, this);
     
Thread Status:
Not open for further replies.

Share This Page