Sending Both Messages Instead Of One

Discussion in 'Plugin Development' started by BurnerDiamond, Mar 19, 2015.

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

    BurnerDiamond

    Code:
       if(e.getItem().getType() == Material.PAPER) {
                if(e.getItem().getItemMeta().getDisplayName() != null) {
                    if(e.getItem().getItemMeta().getDisplayName().equals(main.getConfig().get("books.players." + p.getName() + ".title"))) {
    
    
                        HashMap<Player, Integer> page = new HashMap<Player, Integer>();
    
                        if(page.get(p) == null) {
    
                            page.put(p, 1);
                        }
    
                        if(page.get(p) == 1) {
                            page.
                            p.sendMessage(ChatColor.YELLOW + main.getConfig().getString("books.players." + p.getName() + ".pages.1"));
    
                        }
    
                        if (page.get(p) == 2){
    
                            p.sendMessage(ChatColor.YELLOW + main.getConfig().getString("books.players." + p.getName() + ".pages.2"));
                            page.put(p, 1);
                        }
                    }
                }
            }
        }
    }
    
    I have a problem which it sends both messages instead of one. I'm getting no errors, but it sends both pages.1 and pages.2.

    Thanks!
     
  2. Offline

    RainoBoy97

    1. page.get(p) will always return 1.
    2. You have random "page." which wont even compile.
     
  3. Offline

    MexMaster

    I think you want to declare the HashMap outside this method. Otherwise a new HashMap will be created every time the method runs
     
  4. Offline

    BurnerDiamond

    Thanks for the help but I decided to forget about de hm.

    new code ant help?

    Code:
    if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
                if (e.getItem().getType() == Material.PAPER) {
                    if (e.getItem().getItemMeta().getDisplayName() != null) {
                        if (e.getItem().getItemMeta().getDisplayName().equals(main.getConfig().get("books.players." + p.getName() + "." + e.getItem().getItemMeta().getDisplayName()))) {
    
                            String section = "books.players." + p.getName() + "." + e.getItem().getItemMeta().getDisplayName();
    
                            p.sendMessage(main.getConfig().getString(section + ".pages.1"));
                            p.sendMessage(main.getConfig().getString(section + ".pages.2"));
                        }
                    }
                }
            }
    here is da config:

    Code:
    books:
      players:
        Bladian:
          gg:
            pages:
              '1': ggg
              '2': fffff
          GG:
            pages:
              '1': ffff
              '2': ggggg
          GG!!!:
            pages:
              '1': fff
              '2': hhhhhh
          fdsdsfv:
            pages:
              '1': ff
              '2': fhhbfd
    
    Thanks
     
  5. Offline

    MexMaster

    What's the problem?
    Any errors?
    Try debugging?
     
  6. Offline

    mkezar

    Yes ^^ Debugging is very vital in plugin making
     
    MexMaster likes this.
  7. Offline

    BurnerDiamond

    No errors will try debugging now!

    Looks like everything works. It just doesn't send the message!

    Never mind again!

    Code:
    if (e.getItem().getItemMeta().getDisplayName().equals(main.getConfig().get("books.players." + p.getName() + "." + e.getItem().getItemMeta().getDisplayName()))) {
    Is where ti stops at!

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Mar 21, 2015
  8. Offline

    sgavster

    Have you tried using else if(blah blah blah) {?
     
  9. Offline

    BurnerDiamond

    Yep. It sends a message on the else statement so it's probably something with my config.
     
  10. Offline

    nverdier

  11. Offline

    BurnerDiamond

    I may have found the problem.

    The string path does not return anything.

    It goes to the path but since it doesn't return anything it just doesn't continue the method.

    Not sure how I can fix this. Any help?
     
  12. Offline

    BurnerDiamond

Thread Status:
Not open for further replies.

Share This Page