Problem / Tutorials?

Discussion in 'Plugin Development' started by Kingzuck, Apr 25, 2012.

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

    Kingzuck

    Hey, im learning to write Plugins.
    But i dont no, how :'(
    I tried for example to create a config but it does not work ...
    Code:
    packa[SIZE=3]ge me.False.[/SIZE]Warn;
     
    import java.io.File;
     
    import org.bukkit.configuration.Configuration;
     
    public class ConfigManager {
        public static String ordner = "plugins/Warn";
        public static File ConfigFile = new File(ordner + File.separator + "Player.yml");
        public static Configuration config;
       
        private Configuration loadConfig(){
           
            try{
                        Configuration config = new Configuration(ConfigFile);   
                       
                       
            }
            catch(Exception e){
                           
            }
           
            return null;
       
        }
    }
    
    Where there are good tutorials?
     
  2. Offline

    ItsJerry

  3. Offline

    theguynextdoor

  4. Offline

    Kingzuck

    Okay i have test it, whats wrong ?

    MainWarn:
    Code:
    package me.False.Warn;
    
    
    
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MainWarn extends JavaPlugin {
    
    final FileConfiguration config = this.getConfig();
    @Override
    public void onEnable() {
    System.out.print("[Warn]Enaled");
    
    
    config.addDefault("Warn.Player.Notch.Warns", "0");
    config.options().copyDefaults(true);
    saveConfig();
    
    }
    
    @Override
    public void onDisable() {
    System.out.print("[Warn]Disabled");
    }
    
    public boolean onCommand(CommandSender sender, Command cmd,
    String Commandlabel, String[] args) {
    
    if (sender instanceof Player) {
    
    if (cmd.getName().equalsIgnoreCase("Warn")) {
    if (args.length > 0) {
    config.set("Warn.Player." + args[0] + ".Warns", config.getInt("Warn.Player." + args[0] + ".Warns") + 1);
    }
    if (args.length > 1) {
    config.set("Warn.Player." + args[0] + ".Warns", config.getInt("Warn.Player." + args[0] + ".Warns") + args[1]);
    }
    saveConfig();
    return true;
    }
    
    }
    
    return false;
    }
    
    }
    
    ConfigManager:
    Code:
    package me.False.Warn;
    
    
    import org.bukkit.event.Listener;
    
    public class ConfigManager implements Listener {
    MainWarn plugin;
    
    public ConfigManager(MainWarn instance){
    plugin = instance;
    
    
    
    }
    }
    
    Error:
    Code:
    2012-04-26 10:43:48 [SEVERE] Could not load 'plugins\Warn.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: File cannot be null
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:148)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:183)
    at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:53)
    at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:156)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:422)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:171)
    at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
    at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
    at me.False.Warn.MainWarn.<init>(MainWarn.java:15)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:144)
    ... 8 more
    
     
  5. Offline

    theguynextdoor

    you put the line
    Code:
    final FileConfiguration config = this.getConfig();
    
    outside of your onEnable.

    Put it inside the onEnable method
     
  6. Offline

    Kingzuck

    've already figured out, but thanks
     
Thread Status:
Not open for further replies.

Share This Page