Help with PlayerJoinEvent and GUI

Discussion in 'Plugin Development' started by carbuilder, Aug 3, 2014.

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

    carbuilder

    Im making a plugin to where if a new player joins it gives them this item. I dont want who ever joins to get the item just the new player. and save it in the config file so whenever they come back they dont get another item put in their inventory.
    what am i doing wrong?
    thanks,
    carbuilder

    Code:

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e) {

    //see if they're new
    PlayerInventory pi = e.getPlayer().getInventory();

    if(getConfig().getConfigurationSection(getName()) == null) {
    //add the kit cause they're new
    ItemStack ironpick = new ItemStack(Material.IRON_PICKAXE, 1);
    ironpick.addEnchantment(Enchantment.DURABILITY, 3);
    ItemMeta ironpickmeta = ironpick.getItemMeta();
    ironpickmeta.setDisplayName(ChatColor.DARK_AQUA + "Miner's Pickaxe");
    List<String> lore = new ArrayList<String>();
    lore.add(ChatColor.BLUE + "This pickaxe will take");
    lore.add(ChatColor.BLUE + "you through the");
    lore.add(ChatColor.GOLD + "deepest " + ChatColor.BLUE + "of caves!");
    ironpickmeta.setLore(lore);
    ironpick.setItemMeta(ironpickmeta);
    pi.addItem(ironpick);
    getConfig().createSection(getName());
    }
    }

    oh and the problem is nothing happens whenever i join the server.

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

    Gater12

  3. Offline

    Flamedek

    carbuilder
    There is a great method player#hasPlayedBefore(). That will basicly save you all the config stuff.
    Also you might need to update the inventory after you added the item
     
  4. Offline

    carbuilder

    Thank you both so much! it works great now

    this is my code: http://pastebin.com/yKxeGg6u
    the previous issue worked but now i dont know how to make the gui appear on join without getting any errors. the gui comes up with the correct item and item meta but i click on the item and i can just take it out. and nothing happens:(
    plz help if u can
    thanks,
    carbuilder

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page