Seeing if clicked block is a villager

Discussion in 'Plugin Development' started by XxZHALO13Xx, Dec 19, 2014.

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

    XxZHALO13Xx

    What event would i use to see if a player clicks a villager with a certain name? would i use playerinteractevent? and if so how do i get the name?
     
  2. Konato_K likes this.
  3. Offline

    XxZHALO13Xx

    @AdamQpzm ok thanks

    @AdamQpzm Also would i use a array list or hashmap to save a players toggle to a config. that way when they join they have the same settings

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

    CraftCreeper6

    @XxZHALO13Xx
    Depends, would you like it to survive after restart/reload?
     
  5. Offline

    XxZHALO13Xx

  6. Offline

    CraftCreeper6

  7. Offline

    XxZHALO13Xx

    @CraftCreeper6 yes but how would i write the array list or whatever to a config? I really suck at configs even after reading all the documentation. and how would i like read it when it starts again?
     
  8. Offline

    CraftCreeper6

    @XxZHALO13Xx
    Well, seeing as your new to configs. I would recommend the built in config. You can access it by using the "getConfig()" method. You can use things such as; getConfig().set("path.seperated.by.periods/dots", What you want to set it too. In your case use a boolean (true / false));

    Then save it; saveConfig();
     
  9. Offline

    XxZHALO13Xx

    @CraftCreeper6 do i need to create the path or will it create it if i hard code it?
     
  10. Offline

    CraftCreeper6

    @XxZHALO13Xx
    It will create it for you.

    EDIT: Just type getConfig().set(playerName, value);
     
  11. Offline

    XxZHALO13Xx

    @CraftCreeper6 so like this..
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent e) {
    3. Player p = (Player) e.getWhoClicked();
    4. if (!e.getInventory().getName().equalsIgnoreCase(levelGUI.levelGuiINV.getName())) return;
    5. if (e.getCurrentItem().getItemMeta() == null) return;
    6. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Level 1")){
    7. e.setCancelled(true);
    8. if(addedto1.contains(p.getName())){
    9. p.sendMessage(Core.MAIN + ChatColor.RED + "You are already in Level 1. Please click Level 2.");
    10. return;
    11. }
    12. else{
    13. [B] addedto1.add(p.getName());
    14. p.sendMessage(Core.MAIN + level1EN);
    15. plugin.getConfig().set(p.getName(), true);
    16.  
    17. if(!addedto1.contains(p.getName())){
    18. plugin.getConfig().set(p.getName(), false);[/B]
    19. }
    20. }


    @CraftCreeper6 i dont get errors but nothing saves to config after reload

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

    CraftCreeper6

  13. Offline

    Konato_K

  14. Offline

    XxZHALO13Xx

    @CraftCreeper6 i did.. i saw that and called it later on.. didnt work still doe
     
Thread Status:
Not open for further replies.

Share This Page