Help my plugin does not work on the server

Discussion in 'Spigot Plugin Help' started by jellyf, Jun 20, 2021.

  1. Main class:
    Code (Text):
    package me.kosherdun.main;

    import org.bukkit.NamespacedKey;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.NamespacedKey;
    import org.bukkit.plugin.java.JavaPlugin;

    public final class Main extends JavaPlugin {
        private static Main instance;

        @Override
        public void onEnable() {
            instance = this;
        }


        public static Main getInstance() {
            return instance;
        }

        @Override
        public void onDisable() {

        }
    }
     

    Items class:
    Code (Text):
    package me.kosherdun.main;

    import org.bukkit.*;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.LeatherArmorMeta;

    import java.util.ArrayList;
    import java.util.List;

    public class Items {

        public static ItemStack dragon_set_chestplate;
        public static ItemStack dragon_set_leggings;
        public static ItemStack dragon_set_boots;

        public static void init() {
            crateDRAGONSETCHESTPLATE();
            crateDRAGONSETLEGS();
            crateDRAGONSETBOOTS();
        }

        private static void crateDRAGONSETCHESTPLATE() {
            ItemStack item = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
            LeatherArmorMeta lch = (LeatherArmorMeta) item.getItemMeta();
            lch.setColor(Color.fromBGR(0, 0, 0));
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Dragon Set ChestPlate ");
            List<String> lore = new ArrayList<>();
            lore.add(ChatColor.GOLD + "This Armor Forged By The Dragon Himself");
            lore.add(ChatColor.DARK_GRAY + "This Is Cursed By The Endermen");
            meta.setLore(lore);
            meta.addEnchant(Enchantment.DURABILITY, 100, true);
            meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 10, true);
            item.setItemMeta(lch);
            item.setItemMeta(meta);


           dragon_set_chestplate = item;
            NamespacedKey key = new NamespacedKey(Main.getInstance(), "Dragon_Set_ChestPlate");

            ShapedRecipe recipe = new ShapedRecipe(key, item);

            recipe.shape(
                    "DDD",
                    "DLD",
                    "DDD"
            );

            recipe.setIngredient('D', Material.DIAMOND);
            recipe.setIngredient('L', Material.LEATHER_CHESTPLATE);

            Bukkit.addRecipe(recipe);


        }


        private static void crateDRAGONSETLEGS() {
            ItemStack item = new ItemStack(Material.LEATHER_LEGGINGS, 1);
            LeatherArmorMeta lch = (LeatherArmorMeta) item.getItemMeta();
            lch.setColor(Color.fromBGR(0, 0, 0));
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Dragon Set Leggings ");
            List<String> lore = new ArrayList<>();
            lore.add(ChatColor.GOLD + "This Armor Forged By The Dragon Himself");
            lore.add(ChatColor.DARK_GRAY + "This Is Cursed By The Endermen");
            meta.setLore(lore);
            meta.addEnchant(Enchantment.DURABILITY, 100, true);
            meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 10, true);
            item.setItemMeta(lch);
            item.setItemMeta(meta);

            dragon_set_leggings = item;

            NamespacedKey key = new NamespacedKey(Main.getInstance(), "Dragon_Set_Leggings");

            ShapedRecipe recipe = new ShapedRecipe(key, item);

            recipe.shape(
                    "DDD",
                    "DLD",
                    "DDD"
            );

            recipe.setIngredient('D', Material.EMERALD);
            recipe.setIngredient('L', Material.LEATHER_LEGGINGS);

            Bukkit.addRecipe(recipe);


        }

        private static void crateDRAGONSETBOOTS() {

            ItemStack item = new ItemStack(Material.LEATHER_BOOTS, 1);

            LeatherArmorMeta lch = (LeatherArmorMeta) item.getItemMeta();
            lch.setColor(Color.fromBGR(0, 0, 0));
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Dragon Set Boots ");
            List<String> lore = new ArrayList<>();
            lore.add(ChatColor.GOLD + "This Armor Forged By The Dragon Himself");
            lore.add(ChatColor.DARK_GRAY + "This Is Cursed By The Endermen");
            meta.setLore(lore);
            meta.addEnchant(Enchantment.DURABILITY, 100, true);
            meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 10, true);
            item.setItemMeta(lch);
            item.setItemMeta(meta);
            dragon_set_boots = item;


            NamespacedKey key = new NamespacedKey(Main.getInstance(), "Dragon_Set_Boots");

            ShapedRecipe recipe = new ShapedRecipe(key, item);

            recipe.shape(
                    "DDD",
                    "DLD",
                    "DDD"
            );

            recipe.setIngredient('D', Material.DIAMOND);
            recipe.setIngredient('L', Material.LEATHER_CHESTPLATE);

            Bukkit.addRecipe(recipe);


        }
    }
     
  2. Benz56

    Moderator Supporter

    Call Items.init() in onEnable()

    Other than that please review the Java naming guidelines and practices.
     
  3. like this?

    Code (Text):
    package me.kosherdun.main;


    import org.bukkit.plugin.java.JavaPlugin;


    public final class Main extends JavaPlugin {
        private static Main instance;

        @Override
        public void onEnable() {
            instance = this;
            Items.init();
        }


        public static Main getInstance() {
            return instance;
        }

        @Override
        public void onDisable() {

        }
    }
     
     
  4. No. Move all methods in Items.init to onEnable.
     
  5. Hey would u mind like show me it like write it there (im stupid lol) (p.s do I need to remove the init from the Items class?)
     
  6. ? I have explained exactly.
     
  7. just remove the whole init part and put it on onEnable?
     
  8. Yes
     
  9. sr
    doesn't work am I that stupid

    Code (Text):
    package me.kosherdun.main;


    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;


    public final class Main extends JavaPlugin {
        private static Main instance;

        @Override
        public void onEnable() {
            instance = this;
            public static void init() {
                crateDRAGONSETCHESTPLATE();
                crateDRAGONSETLEGS();
                crateDRAGONSETBOOTS();
            }

       



            }


        public static Main getInstance() {
            return instance;
        }

        @Override
        public void onDisable() {

        }
    }
     
    probably
     
  10. lol no.
     
  11. so how plz can u show me :)
     
  12. Is cleaner to create an instance of the Items class and then calling init.
    Code (Java):

    Items itm = new Items();
    itm.init();
    Put that code in your onEnable method.

    After this, if it doesn't work, it throws any trace on console?
    Do you created the plugin.yml file?
    It shows the plugin when you perform /plugins command?
     
  13. yes I have a check to see the plugin is working it writes in console I'll try what u sent ty
     
    • Friendly Friendly x 1
  14. no it does not work the console isnt printing what I told him to in case it works
    Code (Text):
    package me.kosherdun.main;


    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;


    public final class Main extends JavaPlugin {
        private static Main instance;

        @Override
        public void onEnable() {
            System.out.println("hallo");
            instance = this;
            Items itm = new Items();
            itm.init();





            }


        public static Main getInstance() {
            return instance;
        }

        @Override
        public void onDisable() {

        }
    }
     
    thats what I did maybe im just pepega idk
     
  15. Did you specified your main class in your plugin.yml?

    something like this:

    Code (YAML):
    main: me.kosherdun.main.Main
     
  16. Ya
     
  17. upload_2021-6-20_18-51-48.png
     
  18. the api is 1.17 oof my server is 1.16.5 LOL
     
  19. Is that the problem
     
  20. There is the plugin.yml file in the root of your plugin's jar?

    I say this because seeing your image i can see that maybe you are using maven

    If you are using maven and there is no plugin.yml file in your jar's root try to add this to your pom.xml

    Code (Text):
    <build>
            <resources>
                <resource>
                    <targetPath>.</targetPath>
                    <filtering>true</filtering>
                    <directory>${basedir}/DIRECTORYTHATCONTAINSYOURPLUGINYML</directory>
                    <includes>
                        <include>plugin.yml</include>
                    </includes>
                </resource>
            </resources>
        </build>
    replace DIRECTORYTHATCONTAINSYOURPLUGINYML with the directory route inside your project that contains your plugin.yml file.