I give up ... what is wrong?

Discussion in 'Plugin Development' started by number1_Master, Jun 1, 2012.

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


    EDIT: Figured it out! There was a ';' after the if statement on line 32.

    I am working with fairly simple code, but it is not working. After at least a day's worth of time, I have given up trying.

    What is supposed to happen:
    After the first lightning strike (from Thor's hammer), my code should generate a random number that is at least 10, but at most 35. If Thor's hammer is used that many times (the random number), then a storm comes.

    What is happening:
    Usually a storm comes on the second strike, or doesn't come on all. A few times, it has come on the third strike.

    There AREN'T any errors.

    Here is the code:
    2. // In my ThorMain
    3. public ArrayList<String> enabledHammers = new ArrayList<String>();
    5. //Now into my Listener
    7. @EventHandler
    8. public void onPlayerClick(PlayerInteractEvent e)
    9. {
    10. Player player = e.getPlayer();
    11. if(e.getAction() == Action.LEFT_CLICK_AIR && plugin.enabledHammers.contains(player.getName()) && player.getItemInHand().getTypeId() == plugin.getConfig().getInt("Thor.Hammer Item"))
    12. {
    13. World world = player.getWorld();
    14. Location targetBlock = player.getTargetBlock(null, 300).getLocation();
    15. plugin.commandStrike(world, targetBlock, true);
    16. if(!(hammerStrike.containsKey(player.getName())))
    17. {
    18. hammerStrike.put(player.getName(), 1);
    19. Random randomStorm = new Random();
    20. int storm = randomStorm.nextInt(25);
    21. storm = storm + 10;
    22. // I've tried storm++, ++storm, storm+=10, and even .nextInt(25) +10
    23. stormNumber.put(player.getName(), storm);
    24. return;
    25. }
    26. else
    27. {
    28. int strikes = hammerStrike.get(player.getName());
    29. strikes = strikes + 1;
    30. hammerStrike.put(player.getName(), strikes);
    31. // I've tried strikes++, ++strikes, strikes+=1, and hammerStrike.get(player.getName()+1);
    32. if(hammerStrike.containsValue(stormNumber.get(player.getName())));
    33. {
    34. if(player.getWorld().hasStorm())
    35. {
    36. return;
    37. }
    38. else
    39. {
    40. player.getWorld().setStorm(true);
    41. return;
    42. }
    43. }
    44. }
    45. }
    46. }

    Any ideas? Thanks a million!
  2. Offline


    Can you give us all of the code and in proper indentation?
  3. Offline


    Your code seems fine, but I (and a lot of plugin developers) worked with weather releated projects before and it has worked fine so this will definetly not a bug in Bukkit API.
    My general debug method is if I'm interested in a variable's value I print it to the console.
    Try to print the randomed number if the player isn't in the hashmap yet, but if he is in it then print the new value.
    You're close to your goal, don't give up now :p
    nunber1_Master likes this.
  4. Offline


    OK I'll add the entire method w/ HashMaps. Indentation I have not realized until now. I'll also add that.
  5. instead of
    1. if(hammerStrike.containsValue(stormNumber.get(player.getName())));

    1. if(strikes >= stormNumber.get(player.getName()))
    nunber1_Master likes this.
  6. Offline


  7. can you check what the values of "stormNumber.get(player.getName())" and "strikes" when the storm is generated?
  8. Offline


    After my code adds 10, I made it print out the number.
    The number was 13.
    After my code adds one to the strike, I made it print out the number.
    The number was 2.
  9. Offline


    Can you print what strikes is before it adds one?
  10. Offline


    Try to change @EventHandler into something like:


    I recommend medium priority btw
  11. Offline


    Assuming that you mean medium is "normal", it already defaults to normal priority when only using "@EventHandler".
  12. Offline


    What exactly do you mean?
    In my code, I strike before I check for a weather change.
  13. sometimes, starting from scrats can help, you can always try it, and if it has the same bug, go to this version
  14. Offline


    It has to do with line 32. Something about the check is incorrect.

    EDIT: Figured it out! There was a ';' after that if statement (the statement on line 32).
  15. stupid errors makes big parts of code not working....
    EDIT: whit my IDe (netbeans) I has an option, thats called "format" and that makes that errors visible
  16. Offline


    That's why I use NetBeans :D
  17. Offline


    Use eclipse :D WAY better to me
    nunber1_Master likes this.
  18. Offline


    I used to use netbeans, but then switched to eclipse do to it's nicer format
  19. I must say, that I have never seen an option at ecilse to configure the format, but whit netbeans, you can cofigure the format whit the options
  20. Offline


    By format, I ment like:
    Where windows go
    The color for certain text
    And the fact that (to me) it is a more open environment
    Since I used to have netbeans, I should say it was a really good. After seeing Eclipse, I realized that it was more open ect.
  21. Offline


    i think you should replace to this:
  22. Offline


    Did you even read that it was fixed?
Thread Status:
Not open for further replies.

Share This Page