Solved Java wont cooperate with me anymore ^^

Discussion in 'Plugin Development' started by EvilKittyCat123, May 7, 2014.

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

    EvilKittyCat123

    Okay, so, this is really pissing me off. I've ripped off a little bit of my hair, and it still wont work. BUT, I SWEAR TO GOD THAT IT WORKED 1-2 MONTHS AGO! It used to take only 10 seconds write this code, but now I've used a few DAYS. Please help me...

    Code:java
    1. package me.stripa.NoDrop;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.player.PlayerDropItemEvent;
    8.  
    9. public class noDrop {
    10.  
    11. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    12.  
    13. { //Syntax error, insert "}" to complete MethodBody. If I do that, I have to have a return false here, and then onPlayerDrop wont work.
    14.  
    15. @EventHandler
    16. public void onPlayerDrop(PlayerDropItemEvent event) {
    17. event.setCancelled(true);
    18. } //Same problem..
    19.  
    20.  
    21.  
    22.  
    23. return false;
    24. }
    25. }
    26.  
     
  2. Offline

    mazentheamazin

    EvilKittyCat123
    My brain.. You just put a method, in a method.
    Code:java
    1. @Override
    2. public void onCommand(CommandSender cs, Command c, String l, String[] a) {
    3. return false;
    4. }
    5.  
    6. @EventHandler
    7. public void onDrop(PlayerDropItemEvent e) {
    8. e.setCancelled(true);
    9. }

    Please learn java before you get into the Bukkit API.
     
    thomasb454 likes this.
  3. Offline

    TryB4

    thomasb454, Rocoty and mazentheamazin like this.
  4. Offline

    RawCode

    memory corruption...

    brain cells prone to damage
     
  5. Offline

    TGRHavoc

    @EvilKittyCat123
    Are you 100% sure this worked 2 months ago? This shouldn't have worked at all. I am truly amazed.
     
  6. Offline

    Rocoty

    I think the title of this thread is misleading. It is you who do not cooperate with Java.
     
    xMrPoi, thomasb454, Garris0n and 6 others like this.
  7. Offline

    EvilKittyCat123

    TGRHavoc
    A lot of things wont work now that worked before. I even wrote it down and it doesn't work..
    mazentheamazin
    Still not working, no error messages anywhere. The items still drops.
     
  8. Offline

    Rocoty

    EvilKittyCat123 I know a foolproof method of making this work. But it won't work unless you follow it exactly. All it is is basically some words of wisdom: "If you wanna code Java, learn Java"

    I'm going to bed. This is just depressive.
     
  9. Offline

    EvilKittyCat123

    Rocoty
    All I want to do, is to make a small bukkit plugin just like this. I have done it beforem but now I want to make another one containing the same features. So how come that it works on my other plugin and not on this one.
     
  10. Offline

    desht

    EvilKittyCat123 I can guarantee you that the code you posted has never worked. It won't even compile, let alone do anything useful. What on earth makes you think that sticking an event handler method inside an onCommand() method makes sense?

    If items are still dropping, you probably haven't registered your event handler.
     
  11. Offline

    Necrodoom

    Because said pasted code of yours does not fit any possible Java syntax, and hence could've never worked. Pastebin full class of both plugins please.
     
  12. Offline

    EvilKittyCat123

    desht
    The event handler is registered. I did exactly the same as mazentheamazin, no errors in console or eclipse. But the items still drops..

    And you guys complaining about hwo I haven't spent 2-3 years learning java wont really help my small problem for my small plugin that I have made many times before.
     
  13. Offline

    Necrodoom

  14. Offline

    EvilKittyCat123

    Necrodoom

    Main class:
    Code:java
    1. package me.stripa.NoDrop;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin
    15. implements Listener
    16. {
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18. public static Main plugin;
    19.  
    20. public void onDisable()
    21. {
    22. PluginDescriptionFile pdfFile = getDescription();
    23. this.logger.info(pdfFile.getName() + " Has been disabled! ");
    24. }
    25.  
    26. public void onEnable()
    27. {
    28. PluginDescriptionFile pdfFile = getDescription();
    29. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been enabled! ");
    30. getServer().getPluginManager().registerEvents(this, this);
    31. }
    32.  
    33. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    34. Player player = (Player) sender;
    35.  
    36.  
    37. {
    38.  
    39. if(cmd.getName().equalsIgnoreCase("nodrop"));
    40. if(player.hasPermission("nodrop.main")) {
    41. player.sendMessage(ChatColor.BLUE +"["
    42. + ChatColor.GRAY + "NoDrop"
    43. + ChatColor.BLUE + "] "
    44. + ChatColor.YELLOW + "============ "
    45. + ChatColor.GRAY + "NoDrop version "
    46. + ChatColor.GREEN + "1.0 "
    47. + ChatColor.YELLOW + "============ "
    48. + ChatColor.GRAY + "Bukkit version: "
    49. + ChatColor.GREEN + Bukkit.getVersion() + " "
    50. + ChatColor.GRAY + "Plugin Developer: "
    51. + ChatColor.GREEN + "EvilKittyCat123");
    52.  
    53.  
    54. } else {
    55. player.sendMessage(ChatColor.BLUE + "["
    56. + ChatColor.GRAY + "NoDrop"
    57. + ChatColor.BLUE + "] "
    58. + ChatColor.RED + "You do not have permission!");
    59.  
    60. }
    61.  
    62.  
    63.  
    64.  
    65.  
    66.  
    67.  
    68.  
    69.  
    70.  
    71.  
    72.  
    73.  
    74. return false;
    75.  
    76. }
    77. }
    78. }
    79.  
    80.  
    81.  
    82.  
    83.  
    84.  
    85.  
    86.  
    87.  
    88.  
    89.  
    90.  
    91.  
    92.  
    93.  
    94.  
    95. Class noDrop:
    96.  
    97.  
    98.  
    99.  
    100.  


    Code:java
    1. package me.stripa.NoDrop;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.player.PlayerDropItemEvent;
    7.  
    8. public class noDrop {
    9.  
    10. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    11. return false;
    12.  
    13. }
    14.  
    15.  
    16. @EventHandler
    17. public void onDrop(PlayerDropItemEvent e) {
    18. e.setCancelled(true);
    19. }
    20.  
    21. }
     
  15. EvilKittyCat123 The class you posted did not implement Listener so you either updated a fair amount and not shown us, or you haven't registered it. As requested, please show full and updated code. EDIT: You're registering the main class, not the class that has the event in. Honestly, you might think we're being mean or unhelpful but this sort of thing suggests you're just copying from somewhere without actually understanding what it does.
     
  16. Offline

    Mayoz

    This just hurts in so many ways
     
  17. Offline

    EvilKittyCat123

    AdamQpzm

    Okay, how do I register the event then?

    Mayoz
    Then go away, you're not helping!

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

    mazentheamazin

    EvilKittyCat123
    You don't implement Listener or extend CommandExecutor in that class. Neither do you actually register the event and the command. There is not even a command done in the class, whats the point of the onCommand method?
     
  19. Offline

    EvilKittyCat123

    mazentheamazin
    I had a command there but removed it, forgot to remove the onCommand method :p

    So what would I do in order to get it to work.
     
  20. EvilKittyCat123 See my edited post above. Point is it's difficult to know how to help somebody who doesn't want to accept the simple fact that you have to learn first.
     
  21. Offline

    Mayoz

    Also why aren't you using StringBuilder?
     
  22. Offline

    Necrodoom

    Why is there a 'Class noDrop:' on line 95 of main class?
     
  23. Offline

    mazentheamazin

    Necrodoom
    That was a text placement mistake.
    EvilKittyCat123
    Learn. Java. for. the. love. of. god.
    EDIT: By that I mean generally, to register an event getServer().getPluginManager().registerEvents(listener, plugin);
     
  24. Offline

    Rocoty

    Isn't that obvious? It has been stated indirectly. You register events for that class and implement Listener.
     
    mazentheamazin likes this.
  25. Mayoz I think that efficiency is the least of his worries right now.
     
  26. Offline

    EvilKittyCat123

    Necrodoom
    That was suppose to be above the class noDrop.. :p It's not really in my real class or code.
     
  27. Offline

    Mayoz

    AdamQpzm likes this.
  28. Offline

    EvilKittyCat123

    I know that I suck, you've all already showed me that. But at least help me.
    So I did this:

    Code:java
    1. package me.stripa.NoDrop;
    2.  
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerDropItemEvent;
    6.  
    7. public class noDrop implements Listener{
    8. getServer().getPluginManager().registerEvents(listener, plugin);
    9.  
    10.  
    11. @EventHandler
    12. public void onDrop(PlayerDropItemEvent e) {
    13. e.setCancelled(true);
    14. }
    15.  
    16. }



    Code:java
    1. package me.stripa.NoDrop;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin
    14. {
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static Main plugin;
    17.  
    18. public void onDisable()
    19. {
    20. PluginDescriptionFile pdfFile = getDescription();
    21. this.logger.info(pdfFile.getName() + " Has been disabled! ");
    22. }
    23.  
    24. public void onEnable()
    25. {
    26. PluginDescriptionFile pdfFile = getDescription();
    27. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been enabled! ");
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    31. Player player = (Player) sender;
    32.  
    33.  
    34. {
    35.  
    36. if(cmd.getName().equalsIgnoreCase("nodrop"));
    37. if(player.hasPermission("nodrop.main")) {
    38. player.sendMessage(ChatColor.BLUE +"["
    39. + ChatColor.GRAY + "NoDrop"
    40. + ChatColor.BLUE + "] "
    41. + ChatColor.YELLOW + "============ "
    42. + ChatColor.GRAY + "NoDrop version "
    43. + ChatColor.GREEN + "1.0 "
    44. + ChatColor.YELLOW + "============ "
    45. + ChatColor.GRAY + "Bukkit version: "
    46. + ChatColor.GREEN + Bukkit.getVersion() + " "
    47. + ChatColor.GRAY + "Plugin Developer: "
    48. + ChatColor.GREEN + "EvilKittyCat123");
    49.  
    50.  
    51. } else {
    52. player.sendMessage(ChatColor.BLUE + "["
    53. + ChatColor.GRAY + "NoDrop"
    54. + ChatColor.BLUE + "] "
    55. + ChatColor.RED + "You do not have permission!");
    56.  
    57. }
    58.  
    59.  
    60.  
    61.  
    62. return false;
    63.  
    64. }
    65. }
    66. }
    67.  
    68.  
    69.  
    70.  
    71.  
    72.  
    73.  
    74.  
    75.  
    76.  
    77.  
    78.  
    79.  
    80.  
    81.  
    82.  
    83.  
    84.  
     
  29. Offline

    Necrodoom

    if(cmd.getName().equalsIgnoreCase("nodrop"));

    huh?
     
  30. Offline

    EvilKittyCat123

    Necrodoom
    It's a command, and it works, so don't worry about it..
     
Thread Status:
Not open for further replies.

Share This Page