Solved Need help with a hashmap bug

Discussion in 'Plugin Development' started by Lammazz, Dec 18, 2014.

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

    Lammazz

    So I'm making a reply command (I'm not an idiot with bukkit/java) and for some reason when I try to use the reply command it just sends me the message that I have nobody to reply to.

    Code:
    code removed
    Before you ask, there are no errors and the code is stopping when it checks if the map contains the player name as a key, I've already checked. All help is welcome.
     
    Last edited: Dec 18, 2014
  2. Offline

    mythbusterma

    @Lammazz

    What do you mean "stopping?" Are you saying that the player is not found in the Map? Are you certain there are not multiple instances of this class, and that the HashMap is actually being filled, used debug statements to check the size of the Map,
     
  3. Offline

    Lammazz

    @mythbusterma When I was testing it and I printed out the hashmap, it was empty. But I don't see why it should be.
     
  4. Offline

    mythbusterma

    @Lammazz

    Did you make sure the HashMap#put(...) statement is being reached?
     
  5. Offline

    Lammazz

  6. Offline

    mythbusterma

    @Lammazz

    Where is this class being instantiated? Show that code.
     
  7. Offline

    Lammazz

    @mythbusterma What? The class has nothing to do with it, the commands work but something is going wrong with the hash map and I don't know why
     
  8. Offline

    mythbusterma

    @Lammazz

    Show the code where your class is instantiated.
     
  9. Offline

    Lammazz

    @mythbusterma
    Is this what you're looking for?
    Code:
    public class WhisperCmd implements CommandExecutor {
     
  10. Offline

    TheCodingCat

    I think he means the constructor
    @Lammazz
     
  11. Offline

    Lammazz

  12. Offline

    mythbusterma

    @Lammazz

    Instantiation, as in the invocation of a constructor, e.g. new Class()
     
  13. Offline

    TheCodingCat

    I think @mythbusterma means to show us the part in your onEnable() where you call your constructor
     
  14. Offline

    Lammazz

  15. Offline

    mythbusterma

    @Lammazz

    Then how would you expect the command to be run?
     
  16. Offline

    Lammazz

    @TheCodingCat @mythbusterma I've already said that the command registers and works fine, the only problem is the HASHMAP not registering my command
     
  17. Offline

    Epicballzy

    Why is this needed? It's not relevant to his post and he mentioned his command worked fine.
     
  18. Offline

    Lammazz

    @mythbusterma Look if you don't know why the hashmap is not working please would you kindly, piss off
     
  19. Offline

    mythbusterma

    @Lammazz

    ........I've already told you why the instantiation of this class can cause the issue you describe, now please, post that code.
     
  20. Offline

    TheCodingCat

    thats very rude
    @Lammazz
    we are just trying to help you and you are being disrespectful to @mythbusterma
     
  21. Offline

    mythbusterma

    I'm sorry you can't understand simple Java, but this is very relevant.
     
  22. Offline

    Lammazz

    @TheCodingCat Sorry if I've offended you I didnt mean to.

    @mythbusterma You didn't say anything about how that can cause an issue.

    The only times I use the WhisperCmd in the onEnable is this:
    Code:
    getCommand("whisper").setExecutor(new WhisperCmd());
            getCommand("reply").setExecutor(new WhisperCmd());
     
  23. Offline

    mythbusterma

    @Lammazz

    And there is exactly where your issue is being caused, in those two lines. Sorry I didn't make it clear why, but you're creating two separate instances of WhisperCmd(), each with their own HashMap.
     
Thread Status:
Not open for further replies.

Share This Page