Config issues - What's gone wrong?

Discussion in 'Plugin Development' started by TheMintyMate, Sep 6, 2014.

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

    TheMintyMate

    I have come to a halt on an ongoing project; I have decided to use a config file to store entity UUID's (as .toString()) and their location. Then, when a player goes within a set range of an entity: if the entity has the same UUID, then teleport the entity to the location set in the config. However, as you can guess, the entity isnt being teleported (but the flow is reaching the for statement). It has been a while scince I have used used cofigs, so I am rather rusty.
    Here is all the code related:
    Code:
    @Override
    public void onEnable(){
    iniConfig();
    /*Register Events*/
    getServer().getPluginManager().registerEvents(this, this);
    getLogger().info("Loaded Plugin");
    }
    @Override
    public void onDisable(){
    saveConfig();
    getLogger().info("Unloading Plugin");
    }
    public void iniConfig(){
    FileConfiguration config = getConfig();
    config.addDefault("Entity", null);
    saveConfig();
    }
    
    Here is where I get the saved config data:
    Code:
    if(!(player.getNearbyEntities(1, 1, 1).isEmpty())){
    List<Entity> near = player.getLocation().getWorld().getEntities();
    for(Entity e: near){
    if(e instanceof LivingEntity){
    /*reaches here*/
    String uuid = e.getUniqueId().toString();
    player.sendMessage(getConfig().getString("Entity." + uuid + ".world"));
    /*throws error on this line +  */
    World w = Bukkit.getWorld(getConfig().getString("Entity." + uuid + ".world"));
    double x = getConfig().getDouble("Entity." + uuid + ".x");
                   double y = getConfig().getDouble("Entity." + uuid + ".y");
                   double z = getConfig().getDouble("Entity." + uuid + ".z");
                   float yaw = (float)getConfig().getDouble("Entity." + uuid + ".yaw");
                   float pitch = (float)getConfig().getDouble("Entity." + uuid + ".pitch");
                   Location loc = new Location(w, x, y, z, yaw, pitch);
                   e.teleport(loc);
    }
    }
    }
    
    I append data using this:
    Code:
    addToConfig(horse.getLocation(),horse.getUniqueId());
    
    addToConfig:
    Code:
    public void addToConfig(Location l,UUID u){
    Location location = l;
    String uuid = u.toString();
    getConfig().set("Entity."+uuid+".world", location.getWorld().getName().toString());
    getConfig().set("Entity."+uuid+".x", location.getX());
    getConfig().set("Entity."+uuid+".y", location.getY());
    getConfig().set("Entity."+uuid+".z", location.getZ());
    getConfig().set("Entity."+uuid+".yaw", location.getYaw());
    getConfig().set("Entity."+uuid+".pitch", location.getPitch());
    saveConfig();
    Player[] players = getServer().getOnlinePlayers();
    for(Player player:players){
    player.sendMessage("Successfully updated Config");
    }
    }
    
    Note: Generally speaking config files are meant for server owners to edit. This wont be, in this case.

    I should imagine that I am either appending the data incorrectly, or i am retrieving it incorrectly.

    Thanks for any help,
    - Minty
     
  2. Offline

    Reddeh

    Just wondering why you're using configs if the server dev shouldn't edit it?
    Guessing it's to do with saving data?
     
  3. Offline

    TheMintyMate

    Simply because this plugin isn't intended for public use (I'm not releasing it on BukkitDev). Therefore I am not concerned about it.
    - Minty
     
  4. Offline

    Reddeh

    Ah I see.
     
Thread Status:
Not open for further replies.

Share This Page