Recipes Problem (External Class)

Discussion in 'Plugin Development' started by Taron10LP, Sep 9, 2019.

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

    Taron10LP

    So I have a problem with my recipes in my onEnable Method. Its like 200 lines long. Now I want to have my recipes + registering it in an External Class. How to do It?

    Thx for helping me.
     
  2. Online

    timtower Administrator Administrator Moderator

    @Taron10LP Put them in a different class.
    Give the class a constructor with a JavaPlugin argument (preferred your main class type)
    Then add a function registerRecipes or similar to keep it organized.
     
  3. Offline

    Taron10LP

    @timtower may you send me an example please?
     
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    Taron10LP

    thx

    @timtower sorry I am not rly good at english may you say me how to do it with an Bukkit example?

    Or maybe how to register it in my mainclass.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 10, 2019
  6. Online

    timtower Administrator Administrator Moderator

    @Taron10LP I don't know what you have already so I can't change that to anything else.
     
  7. Offline

    Taron10LP

    @timtower

    My mainclass:
    Code:
    package Main;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import Main.mainclass;
    import Recipes.myL;
    
    public class mainclass extends JavaPlugin {
     
        private mainclass plugin;
     
        public void onEnable() {
            System.out.println("[RPG-Plugin] RPG ready to start!");
            PluginManager pm = Bukkit.getPluginManager();
        }
     
        public void onDisable() {
            System.out.println("[RPG-Plugin] Eine Böse Macht hat die Welt der Fantasie zerstorrt!");
        }
     
        public mainclass getPlugin() {
            return plugin;
        }
    
    }
    and my extaernal recipe class (myL)
    Code:
    package Recipes;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.ShapelessRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.material.MaterialData;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.PluginManager;
    
    public class myL extends Main.mainclass {
     
        public myL() {
             
                ItemStack myL = new ItemStack(Material.LEATHER);
                ItemMeta meta = myL.getItemMeta();
                meta.setDisplayName("§aMystisches Leder");
                ArrayList<String> lore = new ArrayList<>();
                lore.add("§l§aUNGEWÖHNLICH");
                meta.setLore(lore);
                myL.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
             
                ShapedRecipe myLR = new ShapedRecipe(myL);
                myLR.shape(" 1 ", "111", " 1 ");
                myLR.setIngredient('1', Material.LEATHER);
        }
    
    }
    Sry something is in german ;)
     
  8. Online

    timtower Administrator Administrator Moderator

    @Taron10LP getServer().addRecipe(mossycobble);
     
  9. Offline

    Taron10LP

    ? I think this doesnt works I mean thats like when I'm making mossycobble in my onEnable
     
  10. Online

    timtower Administrator Administrator Moderator

    @Taron10LP I copied it from a different thread, it just shows how to register it.
     
  11. Offline

    Taron10LP

    Oh thank you I just did it wrong

    but now there is the problem when I want to crat it ingame it doesnt works I don't see what I did wrong!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Sep 11, 2019
  12. Online

    timtower Administrator Administrator Moderator

    @Taron10LP My vote is on a PluginAlreadyInitializedException.
    Check your logs.
     
  13. Offline

    Taron10LP

  14. Offline

    KarimAKL

    What happens? Does it just not appear when you try to craft it?
    Btw, could you show your current code as well?
     
Thread Status:
Not open for further replies.

Share This Page