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

    DeluXeNationMC

    TGRHavoc Shall i tell him to do that?
     
  2. Offline

    TGRHavoc

    DeluXeNationMC
    Well, if he's still getting the brackets wrong... Yea, he should try learning Java first.
     
  3. Offline

    DeluXeNationMC

    Yes... unfortunately its the truth im going to tell him to learn basic java and come back to the Bukkit API when he is more "Advanced"
     
  4. Offline

    Mayoz

  5. Offline

    TGRHavoc

    Mayoz
    I honestly have no idea... And as to how that worked before... I.. I'm speechless..
     
    DeluXeNationMC likes this.
  6. Offline

    DeluXeNationMC

    Yea i dont really understand that either Eclipse adds them in automatically.

    (I dont think it worked before)
    Edit: Honesly your comment makes me laugh :D

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

    TGRHavoc

    DeluXeNationMC
    No, me neither. If it did then I'm the King of Spain!
     
  8. Offline

    EvilKittyCat123

    Okay, so, I moved on. But now I got another problem. So if anyone could help that'd be great:
    Code:java
    1. @EventHandler
    2. public void onPlayerDrop(PlayerDropItemEvent evt) {
    3. evt.setCancelled(true);
    4. Player player = evt.getPlayer();
    5. player.sendMessage(getConfig().getString("PlayerDropMessage"));
    6. if(player.hasPermission("nodrop.bypass")) {
    7. evt.setCancelled(false); }

    The message from the config gets sent when the player cant drop items, but it also sends the player a message if they have the permission. I tried using } else {, but that did not work. Any ideas?

    I'm stupid and I suck, please help me....?
     
  9. Offline

    Mayoz

    Oh god, not again.
     
    TGRHavoc likes this.
  10. Offline

    EvilKittyCat123

    Instead of throwing it back into my face, how about you help me?
     
  11. Offline

    Mayoz

    How about you post the whole thing, please
     
  12. Offline

    TGRHavoc

    By looks of the code, you're not closing the bracket for the method? Is that correct? If not, post the full code for that method please...
     
  13. Offline

    EvilKittyCat123

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


    Do you want the config as well?

    TGRHavoc
    DeluxeMC told me to add those brackets though..

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

    TGRHavoc

    EvilKittyCat123
    Yes, he was correct. It just looked like the method was incorrect because you didn't post the full code. Anyways
    Code:java
    1. @EventHandler
    2. public void onPlayerDrop(PlayerDropItemEvent evt) {
    3. evt.setCancelled(true);
    4. Player player = evt.getPlayer();
    5. player.sendMessage(getConfig().getString("PlayerDropMessage"));
    6. if(player.hasPermission("nodrop.bypass")) {
    7. evt.setCancelled(false); }
    8.  
    9.  
    10. }

    Try putting the "if(player.hasPermission())" statement at the very top of the method, this will be the fist thing that is checked. Then, in the "if" statement you could put "return;" to make the code stop executing if the player has the permission. This should stop the message from being sent twice...
     
  15. Offline

    Mayoz

    So what's the problem you're trying to fix?

    TGRHavoc
    Shall we do it for him now?

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

    TGRHavoc

    Mayoz
    No, we shouldn't spoonfeed him code when he clearly doesn't grasp the basic concept of Java. We should however, tell him how to fix the issue as at least he has given it a shot...
     
  17. Offline

    EvilKittyCat123

    TGRHavoc
    Using return; makes the code below unreachable.
    Code:java
    1. @EventHandler
    2. public void onPlayerDrop(PlayerDropItemEvent evt) {
    3. Player player = evt.getPlayer();
    4. if(player.hasPermission("nodrop.bypass")) {
    5. evt.setCancelled(false); }
    6. return;
    7. evt.setCancelled(true); //unreachable
    8. player.sendMessage(getConfig().getString("PlayerDropMessage"));
     
  18. Offline

    MrInspector

    Before someone comes in and gives you the full code for everything, bukkits users are not obligated to help you in anyway, you should be happy you got a reply, if you don't want to spend 2-3 years learning java just for bukkit, that shows you just want to jump into the game extremely quick, java isn't only needed for bukkit, put it on your resume when applying for a job, there are lots of jobs that require you to know java, there are a lot of different things to do with java, make a great game, sell it, and you could be rich just like Notch & Minecraft.
     
    Mayoz and TGRHavoc like this.
  19. Offline

    TGRHavoc

    EvilKittyCat123
    -Facepalm-
    Please, pick up a good book on Java... Please.. I suggest "Java for Dummies". I haven't used it myself but, have heard good reviews about it.....
     
  20. Offline

    EvilKittyCat123

    MrInspector
    I Know what java is, I know what it does... -.- I'm not that stupid. I know what I can do with it. I just asked for some help. So either help or keep your comments for yourself.
     
  21. Offline

    TGRHavoc

    EvilKittyCat123
    Right, quiz time! What does this code do:
    Code:java
    1. public void onPlayerDrop(PlayerDropItemEvent evt) {
    2. Player player = evt.getPlayer();
    3. if(player.hasPermission("nodrop.bypass")) {
    4. evt.setCancelled(false); }
    5. return;
    6. evt.setCancelled(true); //unreachable
    7. player.sendMessage(getConfig().getString("PlayerDropMessage"));

    And why is the "return;" always being called?
     
  22. Offline

    EvilKittyCat123

  23. Offline

    MrInspector

    That shows you completly just ignored my post.
     
  24. Offline

    Mayoz


    TGRHavoc
    That's just funny.
     
  25. Offline

    TGRHavoc

    EvilKittyCat123
    Ok... What will this do then?:
    Code:java
    1. if (condition1 == true){
    2. player.sendMessage("Condition1 = true");
    3. player.sendMessage("This, and only this code will run");
    4. }else{
    5. player.sendMessage("Condition1 = false");
    6. player.senMessage("This, and only this, code will run");
    7. }
    8.  
    9. return;
    10. //More code here
     
  26. Offline

    EvilKittyCat123

    Mayoz
    Funny for you, fucking annoying for me.

    TGRHavoc
    if condition1 is true, then the 2 lines of code below will get executed. If the condition1 is false, then the 2 commands at the end will run.. Ahh.
    I think I get it, hold on.

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

    TGRHavoc

    EvilKittyCat123
    Do you now understand why "return" is always being called?
     
  28. Offline

    Mayoz

    TGRHavoc
    Why do you have it return but then have a comment below saying "more code here?"
     
  29. Offline

    EvilKittyCat123

    Nope, but I'm getting close, right?
    Code:java
    1. @EventHandler
    2. public void onPlayerDrop(PlayerDropItemEvent evt) {
    3. Player player = evt.getPlayer();
    4. player.sendMessage(getConfig().getString("PlayerDropMessage"));
    5. evt.setCancelled(true);
    6.  
    7. } else { //Player player = evt.getPlayer();
    8.  
    9. if(player.hasPermission("nodrop.bypass")) { //Player player = evt.getPlayer();
    10. evt.setCancelled(false); } //Player player = evt.getPlayer();
     
  30. Offline

    TGRHavoc

    Mayoz
    To replicate his original code....
     
Thread Status:
Not open for further replies.

Share This Page