What is the best config choice? (Pet plugin)

Discussion in 'Plugin Development' started by Banjer_HD, Nov 19, 2015.

Thread Status:
Not open for further replies.
  1. Hello,
    I am making a pet plugin with: Pet names, Pet Types (And for cats cat types)
    I need to save this in a config.. How can i do this the best?
    Thank you in advance!
     
  2. Offline

    tkuiyeager1

    first of all save the player's pet data in the config with the player's uuid then just set the entity name and custom name and all other things in the config, then when they summon the pet just get the data from the config and spawn the pet.
     
  3. Offline

    Zombie_Striker

    @Banjer_HD
    Depends what you mean by "best".

    If you mean "organized", then you should ...
    1. Create a sub directory.
    2. Create yml files that have the player's uuid as the name of those files
    3. Inside those files, store the pet, player's name, and any other data
    If you mean "memory and space management"
    1. Use the default config.
    2. use the UUID as the first bit to the path
    3. Then store player's pets, names, and other data needed.
     
    tkuiyeager1 likes this.
  4. @tkuiyeager1
    Can you please send some code to help me out? Thanks!
     
  5. Offline

    teej107

  6. @teej107
    Thank you!
    But i need help again xD
    Nothing is spawning..
    What is wrong with this code?:
    Code:
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
                Player p = e.getPlayer();
                if(getConfig().getString("Players." + p.getUniqueId() + ".type") == null || getConfig().getString("Players." + p.getUniqueId() + ".name") == null) {
                
                }else {
                    if(getConfig().getString("Players." + p.getUniqueId() + ".type").toLowerCase() ==  "dog") {
                    Wolf w = (Wolf) p.getWorld().spawnEntity(p.getLocation(), EntityType.WOLF);
                    w.setCustomName(getConfig().getString("Players." + p.getUniqueId() + ".name"));
                    }else if(getConfig().getString("Players." + p.getUniqueId() + ".type").toLowerCase() ==  "ocelot") {
                        Ocelot o = (Ocelot) p.getWorld().spawnEntity(p.getLocation(), EntityType.OCELOT);
                        o.setCustomName(getConfig().getString("Players." + p.getUniqueId() + ".name"));
                    }
                }
        }
    
    Config:
    Code:
    Players:
      4d6f3130-5441-4a10-b46a-99ccedf15035:
        type: dog
        name: test
    
     
  7. Offline

    Zombie_Striker

    Then why not just invert the statement?

    Use equalsignorecase, only use == for Enums
     
  8. Does'nt work..
    Code:
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
                Player p = e.getPlayer();
                if(getConfig().getString("Players." + p.getUniqueId() + ".soort") == null || getConfig().getString("Players." + p.getUniqueId() + ".naam") == null) {
                   
                }else {
                    if(getConfig().getString("Players." + p.getUniqueId() + ".soort").toLowerCase().equalsIgnoreCase("hond")) {
                    Wolf w = (Wolf) p.getWorld().spawnEntity(p.getLocation(), EntityType.WOLF);
                    w.setCustomName(getConfig().getString("Players." + p.getUniqueId() + ".naam"));
                    }else if(getConfig().getString("Players." + p.getUniqueId() + ".soort").toLowerCase().equalsIgnoreCase("kat")) {
                        Ocelot o = (Ocelot) p.getWorld().spawnEntity(p.getLocation(), EntityType.OCELOT);
                        o.setCustomName(getConfig().getString("Players." + p.getUniqueId() + ".naam"));
                    }
                }
        }
    
     
  9. Offline

    Mrs. bwfctower

    And primitives. And if you ever may need to compare references.
     
    Abstract97 likes this.
  10. Offline

    Scimiguy

    Sounds like you're only using serializeable fields
    Could just dump to binary
     
  11. Offline

    teej107

  12. @teej107 I did.. I did a test:
    Code:
    if(getConfig().getString("Players." + p.getUniqueId() + ".soort").toLowerCase().equalsIgnoreCase("dog")) {
                    p.sendMessage("Works");
                    Wolf w = (Wolf) p.getWorld().spawnEntity(p.getLocation(), EntityType.WOLF);
                    w.setCustomName(getConfig().getString("Players." + p.getUniqueId() + ".Name"));
                    }
    
    it send me Works..

    @teej107 Oh Sorry it was my spawn location (facepalm) (Not enough blocks to spawn)
    Thank you all for the great help!

    --------------------------------------------
    UPDATE:
    Pet plugin ready for upload!
    Thanks!
    --------------------------------------------

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

Share This Page