No error...

Discussion in 'Plugin Development' started by EpicBlargh, May 11, 2012.

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

    EpicBlargh

    Show Spoiler

    Code:
    package me;
     
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.DyeColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CraftableMain extends JavaPlugin{
       
        Logger log;
        File configFile;
        FileConfiguration config;
        CraftableMain plugin;
       
        public void onEnable(){
            log = this.getLogger();
            log.info("Craftable enabled.");
            configFile = new File(getDataFolder(), "config.yml");
           
            try {
                firstRun();
            } catch (Exception e) {
                e.printStackTrace();
            }
           
            config = new YamlConfiguration();
            loadYamls();
           
            int mobspawner = plugin.getConfig().getInt("monsterspawner");
            int fire = plugin.getConfig().getInt("fire");
           
            //SPONGE
            ShapedRecipe Sponge = new ShapedRecipe( new ItemStack(Material.SPONGE, 2)).shape(new String[] { " y ", " w ", " c "});
            Sponge.setIngredient('w', Material.WOOL);
            Sponge.setIngredient('y', Material.INK_SACK, (byte) 11);
            Sponge.setIngredient('c', Material.COAL);
            Bukkit.getServer().addRecipe(Sponge);
           
            //GRASS
            ShapedRecipe Grass = new ShapedRecipe( new ItemStack(Material.GRASS, 1)).shape(new String[] { " s ", " d ", "  "});
            Sponge.setIngredient('s', Material.SEEDS);
            Sponge.setIngredient('d', Material.DIRT);
            Bukkit.getServer().addRecipe(Grass);
           
            //COBWEB
            ShapedRecipe Cobweb = new ShapedRecipe( new ItemStack(Material.WEB, 2)).shape(new String[] { "ss ", "ss ", "  "});
            Sponge.setIngredient('s', Material.STRING);
            Bukkit.getServer().addRecipe(Cobweb);
           
            //MOB SPAWNER
            if(mobspawner == 1){
                ShapedRecipe MobSpawner = new ShapedRecipe( new ItemStack(Material.MOB_SPAWNER, 1)).shape(new String[] { "iii", "iei", "iii"});
                Sponge.setIngredient('i', Material.IRON_INGOT);
                Sponge.setIngredient('e', Material.ENDER_PEARL);
                Bukkit.getServer().addRecipe(MobSpawner);
            }
        }
       
        private void firstRun() throws Exception {
            if(!configFile.exists()){
                configFile.getParentFile().mkdirs();
                copy(getResource("config.yml"), configFile);
            }
        }
       
        private void copy(InputStream in, File file) {
            try {
                OutputStream out = new FileOutputStream(file);
                byte[] buf = new byte[1024];
                int len;
                while((len=in.read(buf))>0){
                    out.write(buf,0,len);
                }
                out.close();
                in.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
       
        public void onDisable(){
            log.info("Craftable disabled.");
            saveYamls();
        }
       
        public void saveYamls() {
            try {
                config.save(configFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
       
        public void loadYamls() {
            try {
                config.load(configFile);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    The problem is on the Mob Spawner recipe. It's supposed to check the configuration for the integer, "1".

    Also, no other recipe works. No errors though.
     
  2. The problem is you set ingredients only on "Sponge" :)

    You also don't have to use all 3 strings slots, you don't need to make a string array and don't have to make everything space if you don't need to...

    Easier code:
    Code:
            ShapedRecipe recipe; // do not copy this
    
            recipe = new ShapedRecipe(new ItemStack(Material.SPONGE, 2));
            recipe.shape("y", "w", "c");
            recipe.setIngredient('w', Material.WOOL);
            recipe.setIngredient('y', Material.INK_SACK, (byte) 11);
            recipe.setIngredient('c', Material.COAL);
            getServer().addRecipe(recipe);
    
            // copy above code and modify
    Also, kinda waste space with those load yml functions, they're not required at all... just use saveResource() instead of copy() and all that stuff, then reloadConfig() and then use getConfig().getBoolean("mobspawner") directly in the if().

    But if you *JUST* want to add some recipes for your server, I suggest you use this: http://dev.bukkit.org/server-mods/recipemanager/
     
  3. Offline

    EpicBlargh

    Digi Wow... I feel so dumb. Thanks for your help. I really appreciate it.
     
Thread Status:
Not open for further replies.

Share This Page