Skip to content
This repository

Development

Know it all? Look at the QuickSheet

Introduction

Hello, First of all thanks for checking out the page and thinking about making a Level for LevelCraft. Fortunately making an Level is incredibly easy even if you have a primitive understanding of Java. (Depending on how complex the level is that is.)

FirstStep

A good first step would be to checkout the source of LCMining. (It is fully annotated). It can be found here: https://github.com/samkio/Levelcraft/tree/master/LCMining/src/me/samkio/lcmining If you take a look at that you will see a mere 3 files to control the Level. This is mainly due to the "complex" LevelCraftCore that handles everything so you don't have to! You can also take the LevelTemplate for a quick startup. https://github.com/downloads/samkio/Levelcraft/LCTemplate.zip

Okay lets get started:

Configuration Class

In the main class there are 4 main things you need to add. They are shown below (Annotated). These (if using the level template [Encouraged Greatly]) set up the class files and file names for the configuration.

//Create a configuration.
     final LCConfiguration LCConfiguration = new LCConfiguration(this);
/Create a Configuration File (String).
     public String ConfigurationFileString = "plugins/LevelCraftCore/Configs/Mining.cfg";
//Create a Configuration File(File).
     public File ConfigurationFile = new File("plugins/LevelCraftCore/Configs/Mining.cfg");
//Create a Plugin variable 'thisPlug'
     public Plugin thisPlug;

OnEnable

On the enable event you need to create a configuration file. This is done via the following code: It is recommended you do this first.

//Create a new dirctory structure if not exsits.
        new File("plugins/LevelCraftCore/Configs/").mkdirs();
        try {
            //Create a new configuration file.
            ConfigurationFile.createNewFile();
        } catch (IOException e) {
            logger.log(Level.SEVERE, "[LC] " + e);
        }

We now need to load the configuration. If using the template this is as easy as 2/4 words:

LCConfiguration.loadConfig();

We now need to set a few properties. These are read by the LevelCraftCore and are all necessary.

ReferenceKeys. - These are the reference keys your Level will use. Ie Mining will have keys such as "Mine","M","Mining","Pick". These are used when players type things such as /lvl shout A good number is 1-4. Remember to include the Level Index!

// Set Reference Keys. 1-4 good.
        String[] Args = { "M", "Mining", "Mine", "Pick" };
        getConfiguration().setProperty("ReferenceKeys", Args);

We now need to set the LevelUnlocks. These are called when the player types /lvl unlock . This co-incides with LevelUnlocksLevel. LevelUnlocksLevel is an integer array that is used with each Unlock to deteriming what level the unlock is.

//Set data to be shown on /lvl unlocks <ref>
        String[] Unlocks = { "Wooden Pickaxe = " + LCConfiguration.WoodPick,
                "Stone Pickaxe = " + LCConfiguration.StonePick,
                "Iron Pickaxe = " + LCConfiguration.IronPick,
                "Gold Pickaxe = " + LCConfiguration.GoldPick,
                "Diamond Pickaxe = " + LCConfiguration.DiamondPick };
        //Set data in parallel with Unlocks. (This denotes wethere the user has the unlock or not.)
        int[] UnlocksLevel = { LCConfiguration.WoodPick,
                LCConfiguration.StonePick, LCConfiguration.IronPick,
                LCConfiguration.GoldPick, LCConfiguration.DiamondPick };
//Set the LevelUnlocksLevel to the UnlocksLevel int array.
        getConfiguration().setProperty("LevelUnlocksLevel", UnlocksLevel);
        //Set the LevelUnlocks to the Unlocks string array.
        getConfiguration().setProperty("LevelUnlocks", Unlocks);

Now we need to set the Exp list. This is what is called when the player type /lvl exp This is done via another String array.

//Sets the data for /lvl exp <ref>
        String[] Exp = { "Exp Per Stone " + LCConfiguration.ExpPerStone,
                "Exp Per CobbleStone " + +LCConfiguration.ExpPerCobble,
                "Exp Per RedStone " + LCConfiguration.ExpPerRedstone,
                "Exp Per GoldOre " + +LCConfiguration.ExpPerGoldOre,
                "Exp Per IronOre " + LCConfiguration.ExpPerIronOre,
                "Exp Per CoalOre " + LCConfiguration.ExpPerCoalOre,
                "Exp Per LapisOre " + LCConfiguration.ExpPerLapisOre,
                "Exp Per MossStone " + LCConfiguration.ExpPerMossStone,
                "Exp Per Obsidian " + LCConfiguration.ExpPerObsidian,
                "Exp Per DiamondOre " + LCConfiguration.ExpPerDiamondOre,
                "Exp Per Netherrack " + LCConfiguration.ExpPerNetherrack,
                "Exp Per SandStone " + LCConfiguration.ExpPerSandStone, };
        //Set the LevelExpPer to the Exp Array.
        getConfiguration().setProperty("LevelExpPer", Exp);

The last set of configurations are simplier. They are LevelName,ReferenceIndex and Author. LevelName is the name of the level. The index is the 1-2Character quick code. And the author is you!

// Set Level Name.
        getConfiguration().setProperty("LevelName", "Mining");
// Set Reference Index (1-2 Characters).
        getConfiguration().setProperty("ReferenceIndex", "M");
// Set Author :3.
        getConfiguration().setProperty("Author", "Samkio");

One all of the Plugin Specific's are out of the way we can move on to getting thisPlug and ensuring LevelCraftCore exsists. If it dosn't exsists. State so and disable.

    // Get the plugin that this one is.
        this.thisPlug = this.getServer().getPluginManager().getPlugin("LCMining");
        //Get the plugin that LevelCraftCore is.
        Plugin LevelCraftCore = this.getServer().getPluginManager().getPlugin("LevelCraftCore");
        //If the plugin for LevelCraftCore is null then disable the plugin. If not register the events and state that it is loaded. 
        if (LevelCraftCore == null) {
            logger.log(Level.SEVERE,
                    "[LC] Could not fine LevelCraftCore. Disabling.");
            this.getServer().getPluginManager().disablePlugin(this);
        } else {
            registerEvents();
            logger.log(Level.INFO, "[LC] Level Mining Loaded");

        }

And that concludes the main class. Ofcourse add anything neccessary to your plugin.

LCConfiguration

The LCConfiguration class handles all the variables in your plugin and therefore the configuration. It uses the file/string in the main class. It uses the properties class in LevelCraftCore.

First define a variable:

//TOOLS
    public int WoodPick;
    public int StonePick;...

Then on the loadConfig method add the following:

  //Create new properties file with the file string.
        Properties properties = new Properties(plugin.ConfigurationFileString);
        try {
            //Try to load it. If not return an error.
            properties.load();
        } catch (IOException e) {
            plugin.logger.log(Level.SEVERE,"[LC] "+e);
        }
        //Set variables for TOOLS
        this.WoodPick = properties.getInteger("WoodenPickaxeLevel", 0);
        this.StonePick = properties.getInteger("StonePickaxeLevel", 5);

This will load the properties and write the integers to the file (if they don't exsits). If they do it will return the actual integer writen on the file.

The properties class supports:

public Properties(String fileName) //Initialises the Properties
public void load() throws IOException //Loads a file
public void save() //Saves a file.
public boolean containsKey(String var) //Returns if a key is in the file.
public String getProperty(String var) //Gets the Property of a key.
public void removeKey(String var) //Removes a key.
public boolean keyExists(String key) //If key exists
//STRING
public String getString(String key)  //Get String (No Fullback)
public String getString(String key, String value) //Get String (Fullback)
public void setString(String key, String value) //Sets a string.
//INT
public int getInteger(String key) //Gets integer
public int getInteger(String key, int value) //Gets integer with Fullback
public void setInteger(String key, int value) // Sets integer
//DOUBLE
public double getDouble(String key) //Gets Double
public double getDouble(String key, double value) //Gets Double with Fullback
public void setDouble(String key, double value) //Sets Double
//LONG
public long getLong(String key) //Gets Long
public long getLong(String key, long value) //Gets Long with Fullback
public void setLong(String key, long value) //Sets Long
//BOOLEAN
public boolean getBoolean(String key) //Gets Boolean
public boolean getBoolean(String key, boolean value) //Gets Boolean with Fullback
public void setBoolean(String key, boolean value) // Sets Boolean

Now that is all set up take a look at the QuickSheet for methods on accessing players Level etc.

Thankyou.

Any Queries drop me a line.

Something went wrong with that request. Please try again.