Need Help With WorldCreator.getGeneratorFor()

Discussion in 'Plugin Development' started by The Gaming Grunts, Feb 15, 2014.

Thread Status:
Not open for further replies.
  1. Hey everyone! So in my plugin, I have, at this moment, 2 built in world generators and I want to give players the option to create a world using these generators. So, I created the following method and command:

    Code:java
    1. public static void createGeneratorWorld(String name, Player player, String generator){
    2. WorldCreator.getGeneratorForName(name, generator, player);
    3. //removed unnecessary stuff
    4. }


    Code:java
    1. if (commandLabel.equalsIgnoreCase("world")){
    2. if (args.length > 0){
    3. if (args[0].equalsIgnoreCase("create")){
    4. if (args[2].equalsIgnoreCase("-g")){
    5. WorldCreate.createGeneratorWorld(args[1], p, args[3]);
    6. }


    Now, when I type "/world create someName -g VoidGenerator" the following error is thrown (VoidGenerator is one of the built-in generators):

    Code:
    [16:33:11] [Server thread/INFO]: giantsfan99999 issued server command: /world create void4 -g VoidGenerator
    [16:33:11] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'world' in plugin WorldManager v0.2
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:542) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:929) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:811) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
    Caused by: java.lang.NumberFormatException: For input string: "VoidGenerator"
        at java.lang.NumberFormatException.forInputString(Unknown Source) ~[?:1.7.0_45]
        at java.lang.Integer.parseInt(Unknown Source) ~[?:1.7.0_45]
        at java.lang.Integer.parseInt(Unknown Source) ~[?:1.7.0_45]
        at me.projectx.WorldManager.Commands.WorldCommand.onCommand(WorldCommand.java:34) ~[WorldManager.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-49-g5a2dda2-b2957jnks]
        ... 13 more
    
    I know it's returning null. I read the javadocs for the method, but it confuses me, especially this part:

    The name must be in the "plugin:id" notation, or optionally just "plugin", where "plugin" is the safe-name of a plugin and "id" is an optional unique identifier for the generator you wish to request from the plugin.

    Any help will be much appreciated :)
     
  2. Offline

    xTrollxDudex

    The Gaming Grunts
    Look at the source; it returns null every time, in fact, the return value of the method is null. It uses the getDefaultWorldGenerator method in Plugin which returns null. Or that is, the plugin that is recieve is null. Try WorldManager:VoidGenerator
     
  3. xTrollxDudex
    Same results. Tried typing "/world create someName -g WorldManager:VoidGenerator"
    Here's the new method:
    Code:java
    1. public static ChunkGenerator getGenerator(String name, Player player, String generator){
    2. return WorldCreator.getGeneratorForName(name, generator, player);
    3. }
    4.  
    5. public static void createWorld(String name, Player sender, String gen){
    6. Bukkit.getServer().createWorld(new WorldCreator(name).generator(getGenerator(name, sender, gen)));
    7. }
     
  4. Offline

    xTrollxDudex

    The Gaming Grunts
    That probably wouldn't make a difference anyways, it will return null anytime called.
     
  5. Offline

    Dpasi314

    Just... pointing out that you're trying to parse a word as an integer...
    Not sure if that's suppose to be there or not...
    Caused by: java.lang.NumberFormatException: For input string: "VoidGenerator"
     
  6. xTrollxDudex
    How would I fix it so it doesn't return null? I don't mean to sound like a noob, but it's my first time working with this stuff :p

    Dpasi314
    Whoops that was from another part of the command. I removed that. Does't resolve the problem completely. It doesn't throw an error anymore, but it still won't detect the generator

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    Dpasi314

    If the id is an integer, and each id is associated with some sort of name, I suggest you create your own "parser" to replace the string with it's associated integer.
     
  8. Offline

    xTrollxDudex

    The Gaming Grunts
    Override the getDefaultWorldGenerator(String worldName, String id) method like you do with the onEnable.
     
  9. xTrollxDudex
    Doing this:
    Code:java
    1. public ChunkGenerator getDefaultWorldGenerator(String worldName, String id){
    2. return new VoidGenerator();
    3. }

    will only work for 1 generator. Since I have more than one, will I have to create a method for each one?
     
  10. Offline

    xTrollxDudex

    The Gaming Grunts
    You can't override a method twice can you? You'd have to return a differed generator for a different property.
     
Thread Status:
Not open for further replies.

Share This Page