Help with string GetConfig

Discussion in 'Plugin Development' started by Texgabs, Feb 26, 2016.

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

    Texgabs

    Hello, i have a issue with this option , i make a plugin with custom messages in the config.yml this option
    This option is in my main and works well with strings of this Class but i need change other messages in other class i try with this:
    Code:
    package me.texgabs.magicsorting;
    
    import java.io.File;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.EntityEquipment;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import me.texgabs.magicsorting.SortingHat;
    
    public class SortingHatSort
      extends BukkitRunnable
    {
      private Player p;
      private House house;
      private SortingHat hat;
      private int times;
     
      SortingHatSort(Player p, House house, JavaPlugin plugin)
      {
        this.p = p;
        this.house = house;
        this.hat = ((SortingHat)plugin);
        this.times = 0;
       
        this.hat.setPlayerHouse(p, house);
       
        EntityEquipment ee = p.getEquipment();
        ee.setHelmet(new ItemStack(Material.LEATHER_HELMET));
        ee.setChestplate(new ItemStack(Material.AIR));
        ee.setLeggings(new ItemStack(Material.AIR));
        ee.setBoots(new ItemStack(Material.AIR));
       
        runTaskTimer(plugin, 0L, 50L);
      }
      public void run()
      {
        this.times += 1;
        if (this.times == 1)
        {
          this.p.sendMessage(ChatColor.GRAY + getConfig().getString("Player-No-Found").replaceAll("&","ยง"));
    But in the line getConfig().getString
    I see the warning that the option is not enabled
    also try to import my main class but nothing. could help me please?

    And Sorry for my english not is my native language
     
  2. Offline

    Zombie_Striker

    @Texgabs
    That is because that class is not the main class. Use [MainClassInstance].getConfig().getString()... to get the config instance.
     
  3. Offline

    Texgabs

    Ok . i try this but i can see this error "Cannot make a static reference to the non-static method getConfig() from the type"
     
  4. Offline

    Zombie_Striker

    @Texgabs
    That is why you need the Main classes Instance. Pass the main classes instance through the other class's constructor.
     
  5. Offline

    Texgabs

    Thanks now works excellent!
     
Thread Status:
Not open for further replies.

Share This Page