Solved I need help with my first plugin

Discussion in 'Spigot Plugin Development' started by Giovanni378, Feb 8, 2020.

  1. Hello, I'm creating my very first plugin, and I wanted it to do something very simple, on command /firework, spawn a firework, I've coded these two classes but it throws an error on my server, this is the error:
    Code (Text):
    at me.prova.plugin.Main.onEnable(Main.java:10) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]
    This is my main class
    Code (Text):
    package me.prova.plugin;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import net.md_5.bungee.api.ChatColor;

    public class Main extends JavaPlugin implements Listener{
        public void onEnable(){
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "\nPlugin has been enabled\n");
            getCommand("firework").setExecutor(new FireworkPlugin());
        }
       
        public void onDisable(){
            getServer().getConsoleSender().sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "\nPlugin has been disabled\n");
        }
       
    }
    and this is the other class
    Code (Text):
    package me.prova.plugin;

    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.FireworkEffect.Builder;
    import org.bukkit.FireworkEffect.Type;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.meta.FireworkMeta;

    public class FireworkPlugin implements CommandExecutor, Listener {

        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (command.getName().equalsIgnoreCase("firework")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    Firework fw = player.getWorld().spawn(player.getLocation(), Firework.class);
                    FireworkMeta fwm = fw.getFireworkMeta();
                    Builder builder = FireworkEffect.builder();
                   
                    fwm.addEffect(builder.flicker(true).withColor(Color.BLUE).build());
                    fwm.addEffect(builder.trail(true).build());
                    fwm.addEffect(builder.withFade(Color.SILVER).build());
                    fwm.addEffect(builder.with(Type.BALL).build());
                    fwm.setPower(10);
                    fw.setFireworkMeta(fwm);  
                }
            }
            return true;
        }
           
    }
     
  2. Post the plugin.yml
     
  3. plugin.yml:
    Code (Text):
    name: myFirstTest
    version: 1.0
    main: me.prova.plugin.Main
    commands:
    firework:
    description: Spawns a firework
    usage: /firework
     
  4. Indentation
     
    • Agree Agree x 1
    • Funny Funny x 1
  5. Ok now it works without errors, thank you very much, my main error was that I was trying to use tab in my plugin.yml, so now I used spaces and it works just fine.