Solved getConfig() error

Discussion in 'Plugin Development' started by ZonalYewHD, May 20, 2014.

Thread Status:
Not open for further replies.
  1. I am trying to allow server owners to be able to set the 'no permissions' message, but I repeatedly get an error when using the method
    Code:
    getConfig().getString("no-perm")
    
    The error is saying that the method getConfig() is not defined. How would I define this? I fixed it in another plugin, but it was the first one I did, and is very simple, so I deleted it. I also am using
    Code:
    getConfig().options().copyDefaults(true);
    saveConfig();
    
    in the onEnable(). How would I fix this?
     
  2. Offline

    CraftedShack

    Please post your class.
     
  3. CraftedShack It's not done, but here's what I have so far:
    Code:
    package me.zonalyewhd.econbuy;
     
    import java.util.ArrayList;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
     
    public class EconGod implements CommandExecutor{
     
    public ArrayList<String> godPlayers = new ArrayList<String>();
     
    public boolean onCommand(CommandSender cs, Command cmd, String s,
    String[] args) {
     
    if(cs.hasPermission("ag.god")){
     
    }else{
    cs.sendMessage(ChatColor.DARK_RED + getConfig().getString("no-perm" + ""));
    }
     
    return true;
    }
     
    }
    
     
  4. Offline

    CraftedShack

  5. CraftedShack Fixed it by adding it to my main class. However, I am faced with one other small issue: upon using the class below, I get an error on
    Code:
     onPlayerDamageEvent
    The class is
    Code:
    package me.zonalyewhd.econbuy;
     
    import java.util.ArrayList;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class EconBuy extends JavaPlugin{
    public void onEnable(){
    System.out.println("AGEcon Enabled!");
    getCommand("econ").setExecutor(new EconCommand());
    getCommand("buy").setExecutor(new EconCommandBuy());
    new EconManager(this);
    SLAPI.loadBalances();
    Bukkit.getPluginManager().registerEvents(new PlayerJoin(), this);
    Bukkit.getPluginManager().registerEvents(new EconJump(), this);
    getConfig().options().copyDefaults(true);
    saveConfig();
    }
    public void onDisable(){
    System.out.println("AGEcon Disabled!");
    SLAPI.saveBalances();
    }
     
    public ArrayList<String> godPlayers = new ArrayList<String>(); 
     
    public boolean onCommand(CommandSender cs, Command cmd, String s, String[] args){
     
    if(cmd.getName().equalsIgnoreCase("")){
    if(cs.hasPermission("ag.god")){
    if(args.length == 0 && cs instanceof Player){
    Player p = (Player)cs;
    if(godPlayers.contains(p.getName())){
    godPlayers.remove(p.getName());
    p.sendMessage(ChatColor.GOLD + "God mode set to " + ChatColor.RED + "false");
    }else{
    godPlayers.add(p.getName());
    p.sendMessage(ChatColor.GOLD + "God mode set to " + ChatColor.RED + "true");
    }
    }else if((args.length == 0) && !(cs instanceof Player)){
    cs.sendMessage("You must be a player to use this command! Type /god <player>");
    }if(args.length > 0){
    switch(args.length){
    case 1:
    Player p = Bukkit.getPlayer(args[0]);
    if(p == null){
    cs.sendMessage(ChatColor.RED + "That player is not online!");
    }else{
    if(godPlayers.contains(p.getName())){
    godPlayers.remove(p.getName());
    p.sendMessage(ChatColor.GOLD + "God mode set to " + ChatColor.RED + "false");
    }else{
    godPlayers.add(p.getName());
    p.sendMessage(ChatColor.GOLD + "God mode set to " + ChatColor.RED + "true");
    }
    }
    break;
    }
    }
     
     
     
    }else{
    cs.sendMessage(ChatColor.DARK_RED + getConfig().getString("no-perm").replaceAll("<cmd>", cmd.getName()));
    }
    }
     
    @EventHandler
    public void onPlayerDamageEvent(EntityDamageEvent e){
    if(e.getEntity() instanceof Player){
    Player p = (Player)e.getEntity();
    if(godPlayers.contains(p.getName())){
    e.setCancelled(true);
    }
    }else{
     
    }
    }
    return true;
     
    }
    }
     
    
    I am told that void is an invalid type for onPlayerDamageEvent
     
  6. Offline

    Gater12

    ZonalYewHD
    Place event method outside of onCommand method.
     
  7. Offline

    xTigerRebornx

    ZonalYewHD
    Code:
    @EventHandler
    public void onPlayerDamageEvent(EntityDamageEvent e){
    if(e.getEntity() instanceof Player){
    Player p = (Player)e.getEntity();
    if(godPlayers.contains(p.getName())){
    e.setCancelled(true);
    }
    }else{
     
    }
    }
    return true;
     
    }
    You are trying to return true in a void, problem should be self-explanatory if you know basic Java
     
  8. xTigerRebornx According to Eclipse, the return is outside the event.
     
  9. Offline

    xTigerRebornx

    ZonalYewHD Then I'd see if Gater12 has suggested the right thing (Since you may have put a method in a method)
     
Thread Status:
Not open for further replies.

Share This Page