Why doesn't this work!??!

Discussion in 'Plugin Development' started by EvilKittyCat123, Mar 1, 2014.

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

    EvilKittyCat123

    Hey. I have been sitting 2 days with this small bug, in my small code. And afetr a lot of googling.. I still haven't gotten any results. This code worked before, and now I need help by one of you guys to fix it. So basicly, what I am trying to d, is to cancel an event (PlayerDropItem event). But I get red lines loads of places. Take a look at my code, I added comment's where the errors are and what they say.

    Code:java
    1. package me.stripa.HCC;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import me.stripa.HCC.HCC;
    6.  
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.player.PlayerDropItemEvent;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class HCC extends JavaPlugin{
    16. public final Logger logger = Logger.getLogger("Minecraft");
    17. public static HCC plugin;
    18.  
    19. @Override
    20.  
    21. public void onDisable() {
    22. PluginDescriptionFile pdfFile = this.getDescription();
    23. this.logger.info(pdfFile.getName() + " Has been disabled! ");
    24.  
    25. {
    26.  
    27. }
    28.  
    29.  
    30.  
    31. }
    32.  
    33. @Override
    34. public void onEnable() {
    35. PluginDescriptionFile pdfFile = this.getDescription();
    36. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been enabled! ");
    37.  
    38.  
    39.  
    40.  
    41.  
    42.  
    43. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { //I have a red line under onCommand, and a red line under all the ,'s, and a red line under "]" on string[].
    44. /*onCommand says "Illegal modifier for parameter onCommand; only final is permitted"
    45.   The , says "Syntax error on token ",", ; expected"
    46.   The ] says "Syntax error, insert ";" to complete LocalVariableDeclarationStatement"*/
    47. Player player = (Player) sender;
    48.  
    49. }
    50.  
    51. @EventHandler
    52. public void onPlayerDrop(PlayerDropItemEvent event) { // I also have errors on the (), it says "Syntax error on token ")", ; expected"...
    53. event.setCancelled(true);
    54. }
    55. }
    56.  
    57. {
    58.  
    59. }
    60. }
    61.  
    62.  
    63.  
    64.  
    65.  
    66.  
    67.  
    68.  
    69.  
    70.  
    71. /*Please help, so I can move on with my life...*/
    72.  
    73.  
    74.  
    75.  
    76.  
    77.  
    78.  
    79.  
    80.  
    81.  
    82.  
    83.  
    84.  
    85.  
    86.  
    87.  
    88.  
    89.  
    90.  
    91.  
    92.  
    93.  
    94.  
    95.  
     
  2. Offline

    MooshViolet

    EvilKittyCat123
    The reason why this isnt working is because in your onEnable, do this:
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);

    also, after you have done that, do this instead of what you have:
    Code:java
    1. public class HCC extends JavaPlugin implements Listener{
    2. //All I did was add "implements Listener"

    You do not need the public boolean statement. You have no command for that to be needed.
    Here, I cleaned up your code for you, this is your fixed code:
    Code:java
    1. package me.stripa.HCC;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5.  
    6. import me.stripa.HCC.HCC;
    7.  
    8.  
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerDropItemEvent;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class HCC extends JavaPlugin implements Listener{
    16. public final Logger logger = Logger.getLogger("Minecraft");
    17. public static HCC plugin;
    18.  
    19. @EventHandler
    20. public void onPlayerDrop(PlayerDropItemEvent event){
    21. event.setCancelled(true);
    22. }
    23.  
    24.  
    25.  
    26. @Override
    27. public void onDisable() {
    28. PluginDescriptionFile pdfFile = this.getDescription();
    29. this.logger.info(pdfFile.getName() + " Has been disabled! ");
    30.  
    31. {
    32.  
    33. }
    34.  
    35.  
    36.  
    37. }
    38.  
    39. @Override
    40. public void onEnable() {
    41. PluginDescriptionFile pdfFile = this.getDescription();
    42. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been enabled! ");
    43. getServer().getPluginManager().registerEvents(this, this);
    44.  
    45.  
    46. }
    47.  
    48. {
    49.  
    50. }
    51. }
    52.  

    I hope this helped.
     
  3. Offline

    PlayinCOD2132

    Looking into this...
     
  4. Offline

    MooshViolet

    PlayinCOD2132
    You can delete it because I added it myself. EvilKitty doesnt need a onCommand. I added my own version if you care to delete as some of it is incorrect, thank you
     
  5. Offline

    PlayinCOD2132

    No problem, thanks for helping him.
     
  6. Offline

    EvilKittyCat123

    MooshViolet
    Thanks, it helped. But I was going to add commands for it later, that is why I used it.
     
  7. Offline

    MooshViolet

    EvilKittyCat123
    No problem. Also when you have a boolean, make sure you add a return statement at the end.
     
  8. Offline

    Minesuchtiiii

    You have forget a } after onEnable!!!!
    Look at it!
    It runs into onCommand !!
     
    badboysteee98 likes this.
Thread Status:
Not open for further replies.

Share This Page