HELP!! I cant figure this out!!

Discussion in 'Plugin Development' started by RangerNuk, Oct 4, 2012.

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

    RangerNuk

    Ok, so I have a few simple questions.

    1. how do you generate a config file?
    -Please make this as in depth as possible.

    2. How do you set things that are determined in the config.

    3. How come this doesn't work?? I've imported EVERYTHING!!! (I've imported zombie, entity, and creature) IT doesn't work, please help!!!!!


    if(cmd.getName().equalsIgnoreCase("zombieapocalypse")){
    if(args.length > 1){
    sender.sendMessage("Too many arguments.");
    returnfalse;
    }
    if(args.length < 1){
    sender.sendMessage("Not enough arguments.");
    returnfalse;
    }
    Player s = (Player)sender;
    Player target = s.getServer().getPlayer(args[0]);
    if(target == null){
    sender.sendMessage(" is not online.");
    returnfalse;
    }
    int n = 100;
    for(int i = 1; i<n;i++){
    World.spawnEntity(EntityType.ZOMBIE, args[0]);
    }



    }
     
  2. Offline

    ZeusAllMighty11

    Well for your first question, it's actually pretty easy.


    Either put this in your onEnable() or call a method in your onEnable to generate config.

    Basically it's

    Code:
    File config = new File(getDataFolder() + File.separator + "config.yml");
            
            if(!config.exists()){
                System.out.println(" Generating config. . .");
                
                this.getConfig().addDefault("Path.To.Value", "Test");
     
                
                this.getConfig().options().copyDefaults(true);
                this.saveConfig();
                
            }
    
    Easy made config. To call it, getConfig().get("Path.To.Value");
    Should print out "Test"
     
  3. Offline

    MrFigg

  4. Offline

    RangerNuk

    What the hell?

    Everyone tells me spawnCreature is out, but it's the only one that works for me.

    I don't need that kind of help for the config generate, all I need to know, is how to generate it. and How to make stuff in the plugin determined by it.

    like this-

    spawn_random_pumpkins: true (yes it happens)
    spawn_random_pumpkins: false (no it doesn't)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  5. Offline

    MrFigg

    Make sure you're bukkit version is up to date and spawnEntity should work fine. I think it's kinda new, sense maybe MC 1.2. Don't really know. spawnCreature has been deprecated.
     
  6. Offline

    RangerNuk

    cool, but that doesnt help with config issues...

    generating it-
    and making things customizable inside it-
     
  7. Offline

    MrFigg

  8. Offline

    RangerNuk

    that helps A TON on generating the config, but how do you make stuff determined in the config? See random pumpkin thing above.
     
  9. Offline

    MrFigg

  10. Offline

    RangerNuk

    on the line Basicexampleconfig, can u name this whatever u want?

    This is helping so much thx

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  11. Offline

    MrFigg

    Yea, you can name the class anything, as long as it extends Config.
     
  12. Offline

    RangerNuk

    Um, mr figg? Your config thing seems to work fine, but it doesn't generate.

    Here is the code that generates it (Its inside the onEnable brackets, but it says it needs to put null in the parentheses after config = DarkRangerConfig(WANTS TO PUT NULL HERE);



    Heres the onEnable code.



    try {
    config = new DarkRangerConfig();
    config.init();
    } catch(Exception ex) {
    getLogger().log(Level.SEVERE, "Failed to load config!!! PLugin will now disable.", ex);
    getServer().getPluginManager().disablePlugin(this);
    return;
    }
    }




    Heres the DarkRangerConfig.java



    package DarkRanger;

    import java.io.File;
    import java.util.Vector;
    import org.bukkit.plugin.Plugin;

    public class DarkRangerConfig extends Config {



    public DarkRangerConfig(Plugin plugin) {
    CONFIG_FILE = new File(plugin.getDataFolder(), "DarkRangerConfig.yml");
    CONFIG_HEADER = "DarkRanger Configuration File";
    }





    public String example_string = "Test-Test-Test";
    public Vector example_vector = new Vector(5, 65);
    publicbooleanexample_boolean = true;


    }

     
  13. Offline

    MrFigg

    Change config = new DarkRangerConfig(); to config = new DarkRangerConfig(this);. You need to pass your plugin to your config, so it knows which folder to put it in.
     
  14. Offline

    RangerNuk

    That worked, but now it says its not up to date. I got the latest dev. build but its spazzing out.
     
  15. Offline

    MrFigg

    What's saying it's not up to date? SuperEasyConfig doesn't have anything to do with any version tracking, so it's probably something else you did. If you can post any error messages or warning that would help.
     
  16. Offline

    RangerNuk

    Error log-

    12:47:07 [SEVERE] Error occurred while enabling DarkRanger v0.0.1 (Is it up to date?)
    java.lang.NullPointerException
    at DarkRanger.DarkRangerMain.onEnable(DarkRangerMain.java:45)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:374)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:266)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:248)
    at net.minecraft.server.MinecraftServer.i(MinecraftServer.java:297)
    at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:276)
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:226)
    at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:140)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:377)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
     
  17. Offline

    MrFigg

    Ok, so this isn't really a version error but a NullPointerException. For future reference you might want to read How to read stack-traces.

    Post your code, particularly around line 45 of DarkRangerMain.java, as there's where the NPE is.
     
  18. Offline

    RangerNuk

    Here is the code, around the TRY thing in onEnable was line 45.


    package DarkRanger;




    import org.bukkit.Material;
    import org.bukkit.configuration.InvalidConfigurationException;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    import java.util.logging.Level;
    import java.util.logging.Logger;



    public class DarkRangerMain extends JavaPlugin {

    public DarkRangerConfig config;

    public void onEnable(){

    getLogger().info("If you read the console messages, you would know that some Halloween related commands may be added soon, >:)");
    getLogger().info("Have you ever wondered what a zombie apocalypse would be like?");
    getLogger().info("You may know soon, Halloween verison 0.1.0");
    getLogger().info("DarkRanger's Pack is now enabled");


    getCommand("roast").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("scorch").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("infire").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("fod").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("nuke1").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("nuke2").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("nuke3").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("nuke4").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("nuke5").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("destroy").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("deathban").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("reaper").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("stave").setExecutor(new DarkRangerCommandExecutor(this));
    getCommand("infect").setExecutor(new $Plague(this));
    getCommand("plague").setExecutor(new $Plague(this));
    getCommand("zombieapocalypse").setExecutor(new $ApocalypseCommandHandler(this));
    getCommand("spiderapocalypse").setExecutor(new $ApocalypseCommandHandler(this));
    getCommand("skeletonapocalypse").setExecutor(new $ApocalypseCommandHandler(this));


    try {
    config = new DarkRangerConfig(this);
    config.init();
    } catch(Exception ex) {
    getLogger().log(Level.SEVERE, "Failed to load config!!! PLugin will now disable.", ex);
    getServer().getPluginManager().disablePlugin(this);
    return;
    }







    //End onEnable method
    }







    public void onDisable(){

    getLogger().info("Thanks for using using DarkRanger's Pack");
    getLogger().info("DarkRanger's Pack disabled");
    try {
    config.save();
    } catch (Exception ex) {

    getLogger().log(Level.SEVERE, "Failed to save config, any changes since last save will not be saved");
    //LEFT OFF ON THIS GO BACK TO http://forums.bukkit.org/threads/li...f-codename_bs-awesome-easyconfig-v2-1.100569/ TO FINISH
    }
    }
    //Any other small parts of the plugin go below here VVVV










    }
     
  19. Offline

    MrFigg

    Ok, first off all you should use the [ SYNTAX=JAVA ] tag when posting code when line numbers are important. I really need to know exactly which line was line 45 so I know what throws the error, and whats around line 45 so I know the context. Two separate and important things. I suggest clicking the Code button on the WYSIWYG Editor (the text field where you type your post), pasting the code into the popup textarea, clicking ok, then changing the [ CODE ] tag to [ SYNTAX=JAVA ] and the [ /CODE ] tag to [ / SYNTAX ].

    Second your CommandExecutors are taking up way more memory than they need to. The way you have it now you make a new instance for every command, but you only need one.
    Code:
    // Add after public DarkRangerConfig config;
    public DarkRangerCommandExecutor darkRangerCommandExecutor;
    public $Plague plague;
    public $ApocalypseCommandHandler apocalypseCommandHandler;
     
    // Replace current setExecutors
    darkRangerCommandExecutor = new DarkRangerCommandExecutor(this);
    getCommand("roast").setExecutor(darkRangerCommandExecutor);
    getCommand("scorch").setExecutor(darkRangerCommandExecutor);
    getCommand("infire").setExecutor(darkRangerCommandExecutor);
    getCommand("fod").setExecutor(darkRangerCommandExecutor);
    getCommand("nuke1").setExecutor(darkRangerCommandExecutor);
    getCommand("nuke2").setExecutor(darkRangerCommandExecutor);
    getCommand("nuke3").setExecutor(darkRangerCommandExecutor);
    getCommand("nuke4").setExecutor(darkRangerCommandExecutor);
    getCommand("nuke5").setExecutor(darkRangerCommandExecutor);
    getCommand("destroy").setExecutor(darkRangerCommandExecutor);
    getCommand("deathban").setExecutor(darkRangerCommandExecutor);
    getCommand("reaper").setExecutor(darkRangerCommandExecutor);
    getCommand("stave").setExecutor(darkRangerCommandExecutor);
    plague = new $Plague(this);
    getCommand("infect").setExecutor(plague);
    getCommand("plague").setExecutor(plague);
    apocalypseCommandHandler = new $ApocalypseCommandHandler(this);
    getCommand("zombieapocalypse").setExecutor(apocalypseCommandHandler);
    getCommand("spiderapocalypse").setExecutor(apocalypseCommandHandler);
    getCommand("skeletonapocalypse").setExecutor(apocalypseCommandHandler);
     
  20. Offline

    RangerNuk

    OK, heres the code. I'll fix the executors later.

    Code:JAVA
    1. package DarkRanger;
    2.  
    3.  
    4.  
    5.  
    6. import org.bukkit.Material;
    7. import org.bukkit.configuration.InvalidConfigurationException;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.player.PlayerJoinEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. import java.util.logging.Level;
    13. import java.util.logging.Logger;
    14.  
    15.  
    16.  
    17. public class DarkRangerMain extends JavaPlugin {
    18.  
    19. public DarkRangerConfig config;
    20.  
    21. public void onEnable(){
    22.  
    23. getLogger().info("If you read the console messages, you would know that some Halloween related commands may be added soon, >:)");
    24. getLogger().info("Have you ever wondered what a zombie apocalypse would be like?");
    25. getLogger().info("You may know soon, Halloween verison 0.1.0");
    26. getLogger().info("DarkRanger's Pack is now enabled");
    27.  
    28.  
    29. getCommand("roast").setExecutor(new DarkRangerCommandExecutor(this));
    30. getCommand("scorch").setExecutor(new DarkRangerCommandExecutor(this));
    31. getCommand("infire").setExecutor(new DarkRangerCommandExecutor(this));
    32. getCommand("fod").setExecutor(new DarkRangerCommandExecutor(this));
    33. getCommand("nuke1").setExecutor(new DarkRangerCommandExecutor(this));
    34. getCommand("nuke2").setExecutor(new DarkRangerCommandExecutor(this));
    35. getCommand("nuke3").setExecutor(new DarkRangerCommandExecutor(this));
    36. getCommand("nuke4").setExecutor(new DarkRangerCommandExecutor(this));
    37. getCommand("nuke5").setExecutor(new DarkRangerCommandExecutor(this));
    38. getCommand("destroy").setExecutor(new DarkRangerCommandExecutor(this));
    39. getCommand("deathban").setExecutor(new DarkRangerCommandExecutor(this));
    40. getCommand("reaper").setExecutor(new DarkRangerCommandExecutor(this));
    41. getCommand("stave").setExecutor(new DarkRangerCommandExecutor(this));
    42. getCommand("infect").setExecutor(new $Plague(this));
    43. getCommand("plague").setExecutor(new $Plague(this));
    44. getCommand("zombieapocalypse").setExecutor(new $ApocalypseCommandHandler(this));
    45. getCommand("spiderapocalypse").setExecutor(new $ApocalypseCommandHandler(this));
    46. getCommand("skeletonapocalypse").setExecutor(new $ApocalypseCommandHandler(this));
    47.  
    48.  
    49. try {
    50. config = new DarkRangerConfig(this);
    51. config.init();
    52. } catch(Exception ex) {
    53. getLogger().log(Level.SEVERE, "Failed to load config!!! PLugin will now disable.", ex);
    54. getServer().getPluginManager().disablePlugin(this);
    55. return;
    56. }
    57.  
    58.  
    59.  
    60.  
    61.  
    62.  
    63.  
    64. //End onEnable method
    65. }
    66.  
    67.  
    68.  
    69.  
    70.  
    71.  
    72.  
    73. public void onDisable(){
    74.  
    75. getLogger().info("Thanks for using using DarkRanger's Pack");
    76. getLogger().info("DarkRanger's Pack disabled");
    77. try {
    78. config.save();
    79. } catch (Exception ex) {
    80.  
    81. getLogger().log(Level.SEVERE, "Failed to save config, any changes since last save will not be saved");
    82. //LEFT OFF ON THIS GO BACK TO [url]http://forums.bukkit.org/threads/lib-supereasyconfig-v1-2-based-off-of-codename_bs-awesome-easyconfig-v2-1.100569/[/url] TO FINISH
    83. }
    84. }
    85. //Any other small parts of the plugin go below here VVVV
    86.  
    87.  
    88.  
    89.  
    90.  
    91.  
    92.  
    93.  
    94.  
    95.  
    96. }
    97.  
    98.  
    99.  
    100.  
    101.  
    102.  
    103.  
    104.  
     
  21. Offline

    MrFigg

    So apparently the problem is that the command 'spiderapocalypse' isn't defined correctly in your plugin.yml.
     
  22. Offline

    RangerNuk

    O wow, I hadn't added it yet, how stupid!! Lol. Hey, do u know anything about minecraft modding?
     
  23. Offline

    MrFigg

    Sorry, not my area. I've only dealt with bukkit plugins so far. You can ask someone else here, or you might want to check out the Minecraft Forum or the Spout Forum. Both will probably have more people dealing with client modding then the bukkit forum.
     
  24. Offline

    RangerNuk

    OK, cool, 2 questions,

    1. How do you make words into links? like if you click Minecraft forum, its a link, instead of http//: ect. ect.

    2. In the latest bukkit, how do you make something return false if the player is offline?

    It used 2 work but now it doesn't when you use if(target == null){} its a npe

    ?????
     
  25. Offline

    MrFigg

    1. There's a button in the WYSIWYG Editor that looks like a chain, that's the link button. Type some text, highlight it, then hit that button. A textfield will pop up and you past your link.

    2. I didn't read it but there is a thread titled Simple Question about, "if(target == null)" that's marked as solved. Look there.
     
  26. Offline

    RangerNuk

    K, thanks, I read the config value thing but still didn't get it. I'm wondering how to make stuff determinable by the config in a command. If in the config it says Death-For-Diseases: true/false,
    How would I put that in the command?


    target.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 1000, 3));
    target.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 1000, 1));
    target.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 1000, 1));
    target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1000, 1));
    target.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 1000, 1));
    target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1000, 3));



    If I add something like if(config == true("Death-For-Diseases"){
    target.setHealth(0);
    }

    Maybe that?
     
  27. Offline

    MrFigg

    Assuming you added the variable to the config;
    Code:
    if(config.Death-For-Diseases) {
        target.setHealth(0);
    }
    Btw, when naming variables you really shouldn't use dashes. And usually you want to have the first character be lower case. If I had to name that variable it would be deathForDiseases.
     
  28. Offline

    RangerNuk

    so, um, how do I add the variable to the config,

    ps, I did everything your turtorial said, it didn't work.

    It couldn't generate the config.
     
  29. Offline

    MrFigg

    Did you add deathForDiseases to DarkRangerConfig? i.e. ;
    Code:
    public class DarkRangerConfig extends Config {
     
        public DarkRangerConfig(Plugin plugin) {
            CONFIG_FILE = new File(plugin.getDataFolder(), "DarkRangerConfig.yml");
            CONFIG_HEADER = "DarkRanger Configuration File";
        }
     
        public boolean deathForDiseases = false;
        // ADD ANY VARIABLES YOU WANT HERE...
        // Kinda thought that would be obvious
    }
    And at this point I'm sorry to say that if you can't figure it out on your own I really cant help any further. I feel like I've given you all the pieces you need. You might want to make yourself more familiar with java programming in general before continuing with bukkit plugin development.
     
  30. Offline

    RangerNuk

    ok, I get the adding variables, but I don't get how to make the variable influence the code.

    That is what i cant figure out.
     
Thread Status:
Not open for further replies.

Share This Page