Referring to a custom Generator in code

Discussion in 'Plugin Development' started by JeroenV, Dec 29, 2012.

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

    JeroenV

    I'm trying to create a new world based that uses the VoidGenerator plugin. However I'm unsure if I can refer to it using a string like I did in the code right under this text or do I need to implement the generator into my code entirely in order to use it? (Wich I'm unsure how to do)

    Code:
            WorldCreator c = new WorldCreator(worldname);
            c.generator("VoidGenerator");
            World world = c.createWorld();    
    If it helps I can say that I want every world to be genned with VoidGenerator, I previously thought I could use bukkit.yml 'Generator:' for this, however that doesn't work either. Could it be that I have placed it in the wrong spot, or is just that it doesn't work on a global level?

    Bukkit.yml:





    Greets,
    Jeroen V.
     
  2. Offline

    fireblast709

    Afaik you would have to use the other plugin (the one in which the generator is defined) and just create an instance of their generator
     
  3. Offline

    JeroenV

    There is no way to let bukkit.yml use the generator for all worlds? For example, how does multiverse do this? I heard it can use external generators.
     
  4. Offline

    fireblast709

    Code:java
    1. @Override
    2. public ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) {
    3. if (generator == null) {
    4. return null;
    5. }
    6.  
    7. Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
    8. if (myPlugin == null) {
    9. return null;
    10. } else {
    11. return myPlugin.getDefaultWorldGenerator(worldName, generatorID);
    12. }
    13. }
    That is what MultiVerse does (long live opensource code). String generator is just the plugin name, and they call getDefaultWorldGenerator(), which should be defined in the main class of the generator plugin
     
  5. Offline

    JeroenV

    I've going through some codes and googling some stuff, now this is where I'm at:

    Code:
            WorldCreator c = new WorldCreator(worldname);
            c.environment();
            Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin("NullTerrain");
            c.generator(myPlugin.getDefaultWorldGenerator(worldname,null));
            World world = c.createWorld();    
    However, for some reason it still wont use NullTerrain as generator for the world.

    Alright, after some more trying I decided to just copy the class over (because it's so small and it's opensource). But how do I actually use this as a c.generator()?


    Here's the class:
    Code:
    public class NullGenerator extends ChunkGenerator{
     
     
        public byte[] generate(World world, Random random, int cx, int cz)
        {
        return new byte[32768];
        }
     
        @Override
        public Location getFixedSpawnLocation(World world, Random random)
        {
       
        return new Location(world, 0, 64, 0);
        }
     
    }
    
    Here's once again what I'm trying to do:
    Code:
            WorldCreator c = new WorldCreator(worldname);
            World world = c.createWorld();    
    I have tried this btw:
    Code:
    c.generator(new NullGenerator());
    But that didn't work either.

    Does anyone know what's wrong here? It would be a great help for me.

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

    GodzOfMadness

    Is it just not working (doing nothing) or giving errors (in console)?
    if so print out the console message :)
     
  7. Offline

    JeroenV

    Nope no errors. It makes the world like you'd expect but it uses the default generator.
     
  8. Offline

    GodzOfMadness

    Not experienced with chunk generation mabe
    someone else on the forums may help you :)
     
  9. Offline

    fireblast709

    Have you tried overriding the getDefaultChunkGenerator in the NullTerain plugin ;D
     
  10. Offline

    JeroenV

    I'm not sure how that would help me though?
     
  11. Offline

    fireblast709

    well in the snippet at replt #5 you used getDefaultWorldGenerator(). If you don't override that to get the instance, it would fail (and give you the default worldgenerator ;3). Btw can you post what you tried using c.generator(new NullGenerator())?
     
  12. Offline

    JeroenV

    Ah that makes sense yeah :) (can't believe I forgot that.)

    About using: c.generator(New NullGenerator()). All I did was put that line of code there to define the chunkgenerator, I had the 'NullGenerator' class (wich extends ChunkGenerator) copied over to my project.

    I'm going to try overriding it right now, and see if it works :)

    When using this method:

    Code:
        @Override
        public org.bukkit.generator.ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) {
        if (generator == null) {
        return null;
        }
     
        Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
        if (myPlugin == null) {
        return null;
        } else {
        return myPlugin.getDefaultWorldGenerator(worldName, generatorID);
        }
        }
    It keeps telling me that it must override or implement a supertype method, as a quickfix Eclipse is telling me to remove the @Override. Is there something I need to implement or extend in the class for this to work, like implementing/extending chunkgenerator?

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

    fireblast709

    I ment getDefaultWorldGenerator() inside the plugin
     
  14. Offline

    JeroenV

    Well it should be since multiverse is recommending NullTerrain to be used with their generator command. I've looked through its source code and it does have it in there.

    The plugin does give me an error on startup saying there's no such method as getconfiguration(..) but I figured after looking into the source code that only makes it so that it doesn't log its version number to the console in onEnable as it all works fine if I implement 'NullTerrain' as generator in bukkit.yml.

    Let me get the mainclass of NullTerrain.

    Here's a link to its source code (it's really small):

    https://github.com/Elizacat/NullTerrain/tree/master/src/main/java/uk/me/elizabethmyers/nullterrain

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

    fireblast709

    For your plugin:
    Code:java
    1. public ChunkGenerator getGenerator(String generator)
    2. {
    3. if(generator == null)
    4. {
    5. return null;
    6. }
    7. JavaPlugin generatorPlugin = Bukkit.getPluginManager().getPlugin(generator);
    8. if(generatorPlugin == null)
    9. {
    10. return null;
    11. }
    12. return generatorPlugin.getDefaultWorldGenerator();
    13. }
     
  16. Offline

    JeroenV

    fireblast709
    Great, everything works now :D thank you so much.
     
Thread Status:
Not open for further replies.

Share This Page