Config.yml not creating:( plz help

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

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

    carbuilder

    The rest of my code works great except this one event. I need the config to save the player's name and it doesnt create the config file. the messages are popping up in chat though.

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3.  
    4. //see if they're new
    5. Player player = e.getPlayer();
    6.  
    7.  
    8. if(!e.getPlayer().hasPlayedBefore()) {
    9. getConfig().createSection(getName());
    10. saveConfig();
    11.  
    12. player.sendMessage(ChatColor.GOLD + "Welcome to the server " + ChatColor.RED + e.getPlayer().getDisplayName() + ChatColor.GOLD + "!");
    13. player.sendMessage(ChatColor.DARK_BLUE + "------" + ChatColor.DARK_AQUA + "Available Kits" + ChatColor.DARK_BLUE + "------");
    14. player.sendMessage(ChatColor.GREEN + "Miner");
    15. player.sendMessage(ChatColor.GREEN + "Soldier");
    16. player.sendMessage(ChatColor.GREEN + "Chemist");
    17. player.sendMessage(ChatColor.GREEN + "Farmer");
    18. player.sendMessage(ChatColor.GREEN + "Craftsman");
    19. player.sendMessage(ChatColor.GREEN + "Default");
    20. player.sendMessage(ChatColor.DARK_RED + "--------------------------------");
    21. player.sendMessage(ChatColor.GOLD + "Do /kits <kit name> to get the kit! You may also buy more kits in-game by doing /kits buy <kit name> will allow you to buy the kit. Or you can do /kits for info about each kit.");
    22.  
    23.  
    24. }
    25. if(player.hasPlayedBefore()) {
    26. player.sendMessage(ChatColor.GOLD + "Welcome back to the server " + ChatColor.BLUE + player.getDisplayName() + ChatColor.GOLD + "!" );
    27. player.sendMessage(ChatColor.RED + "[Kits]" + ChatColor.DARK_AQUA + " Kits are available for sale! Do /kits for more info.");
    28.  
    29.  
    30.  
    31. }
    32. }


    Thanks so much in advance,
    carbuilder

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

    xTigerRebornx

    carbuilder
    Code:
     getConfig().createSection(getName());
    You are calling getName() here, what is that method? Perhaps you met Player#getName(), in which case you should be using UUIDs to store data as name changes are coming soon meaning names are no longer unique (thus not making them a valid way of storing data for a Player)
     
  3. Offline

    carbuilder

    oh ok i see. I tried replacing it with player.getName() and it doesn't work. i will try to find outhow to use UUIDs thank you
     
  4. Offline

    KaitouKidFTW

    Code:java
    1. if(!getConfig().contains(player.getName())){
    2. getConfig().set("Player", player.getName());
    3. saveConfig();
    4. }


    Also make sure you do this on your onEnable(){

    Code:java
    1. public void onEnable(){
    2.  
    3. getConfig().options().copyDefaults(true);
    4. saveConfig();
    5. }
     
  5. Offline

    carbuilder

    thnx so much that helped but heres the real problem. if the player is not new i want them to be able to get the kit but whener i sign in as a new player i can get the kit more than once. this is only a tiny section of the code too. also, their UUID was stored correctly in the config i checked. plz help
    thanks, carbuilder

    Code:java
    1. if(!player.hasPlayedBefore()) {
    2. if(args.length == 1) {
    3. if(args[0].equals("miner")) {
    4. if(getConfig().contains(uuid)) {
    5. sender.sendMessage(ChatColor.RED + "The free kit is for new players only!");
    6. return true;
    7. }
    8. //miner kit
    9. ItemStack ironpick = new ItemStack(Material.IRON_PICKAXE, 1);
    10. ironpick.addEnchantment(Enchantment.DURABILITY, 3);
    11. ironpick.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 1);
    12. ItemMeta ironpickmeta = ironpick.getItemMeta();
    13. ironpickmeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Miner's Pickaxe");
    14. List<String> lore = new ArrayList<String>();
    15. lore.add(ChatColor.BLUE + "This pickaxe will take");
    16. lore.add(ChatColor.BLUE + "you through the");
    17. lore.add(ChatColor.GOLD + "deepest " + ChatColor.BLUE + "of caves!");
    18. ironpickmeta.setLore(lore);
    19. ironpick.setItemMeta(ironpickmeta);
    20. pi.addItem(ironpick);
     
  6. Offline

    KaitouKidFTW

    Check if the player's UUID is in config and if it is then deny them from getting the kit multiple times.
     
  7. Offline

    carbuilder

    nothing is working ive tried everything and ive been working on this all day long so i rly need some help

    here is the code

    Code:java
    1. if(!player.hasPlayedBefore()) {
    2. if(args.length == 1) {
    3. if(args[0].equals("miner")) {
    4. if(getConfig().contains(uuid)) {
    5. sender.sendMessage(ChatColor.RED + "The free kit is for new players only!");
    6. return true;
    7. }
    8.  
    9. //miner kit
    10. ItemStack ironpick = new ItemStack(Material.IRON_PICKAXE, 1);
    11. ironpick.addEnchantment(Enchantment.DURABILITY, 3);
    12. ironpick.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 1);
    13. ItemMeta ironpickmeta = ironpick.getItemMeta();
    14. ironpickmeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Miner's Pickaxe");
    15. List<String> lore = new ArrayList<String>();
    16. lore.add(ChatColor.BLUE + "This pickaxe will take");
    17. lore.add(ChatColor.BLUE + "you through the");
    18. lore.add(ChatColor.GOLD + "deepest " + ChatColor.BLUE + "of caves!");
    19. ironpickmeta.setLore(lore);
    20. ironpick.setItemMeta(ironpickmeta);
    21. pi.addItem(ironpick);
    22. ItemStack miners = new ItemStack(Material.STONE_SWORD);
    23. ItemMeta minersmeta = miners.getItemMeta();
    24. minersmeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Miner's Sword");
    25. miners.setItemMeta(minersmeta);
    26. pi.addItem(miners);
    27. pi.addItem(new ItemStack(Material.COOKED_BEEF, 10));
    28. pi.addItem(new ItemStack(Material.WOOD, 32));
    29. pi.addItem(new ItemStack(Material.TORCH, 32));
    30. pi.addItem(new ItemStack(Material.WORKBENCH, 1));
    31. player.sendMessage(ChatColor.GOLD + "You got your " + ChatColor.BLUE + args[0] + ChatColor.GOLD + " kit!");
    32. getConfig().getConfigurationSection(uuid);
    33. getConfig().createSection(uuid);
    34. saveConfig();
    35. }
    36.  
    37. return true;
    38. }


    oh and this is above it
    Code:java
    1. String uuid = player.getUniqueId().toString();


    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