Command Problems

Discussion in 'Plugin Development' started by Ugonnadie, Oct 22, 2020.

  1. Offline

    Ugonnadie

    Hey guys, I keep getting an error. I've done plugins similar to this in the past and have never encountered this error. Please help.
    Main:
    Code:
    package me.Ugonnalive.ElytraJousting;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
       
        @Override
        public void onEnable() {
            getCommand("joust").setExecutor(new Command1());
            Command1.plugin = this;
        }
    }
    Command1:
    Code:
    package me.Ugonnalive.ElytraJousting;
    
    import java.util.Collection;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    
    public class Command1 implements CommandExecutor {
       
    
        @Override
        public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) {
            if (sender instanceof Player) {
                runnable();
            }
            return true;
        }
       
        static JavaPlugin plugin;
        ItemStack arrow = new ItemStack(Material.ARROW, 1);
        ItemStack crossbow = new ItemStack(Material.CROSSBOW, 1);
        ItemStack sword = new ItemStack(Material.STONE_SWORD, 1);
        ItemStack helmet = new ItemStack(Material.IRON_HELMET, 1);
        ItemStack leggings = new ItemStack(Material.IRON_LEGGINGS, 1);
        ItemStack boots = new ItemStack(Material.IRON_BOOTS, 1);
       
        public void runnable() {
            new BukkitRunnable() {
               
                @Override
                public void run() {
                    Collection<? extends Player> players = Bukkit.getOnlinePlayers();
                    ItemStack elytra = new ItemStack(Material.ELYTRA, 1);
    
                    for (Player player: players) {
                        player.getInventory().setHelmet(helmet);
                        player.getInventory().setLeggings(leggings);
                        player.getInventory().setBoots(boots);
                        player.getInventory().setChestplate(elytra);
                        player.setGliding(true);
                       
                        if(player.getInventory().getItem(1) != sword) {
                            player.getInventory().setItem(1, sword);
                        }
                        if(player.getInventory().getItem(2) != crossbow) {
                            player.getInventory().setItem(2, crossbow);
                        }
                        if(player.getInventory().getItem(9) != arrow) {
                            player.getInventory().setItem(9, arrow);
                        }
    
                    }
                }   
            }.runTaskTimerAsynchronously(plugin, 0, 1);
        }
    }
    
    plugin.yml:
    Code:
    name: ElytraJousting
    main: me.Ugonnalive.ElytraJousting.Main
    version: 1.0
    author: me
    api-version: 1.16
    commands:
      glide:
        description: Elytra Jousting.
        usage: /joust
    Error:
    Code:
    [22:06:41] [Server thread/ERROR]: Error occurred while enabling ElytraJousting v1.0 (Is it up to date?)
    java.lang.NullPointerException: null
            at me.Ugonnalive.ElytraJousting.Main.onEnable(Main.java:11) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at org.bukkit.craftbukkit.v1_16_R2.CraftServer.enablePlugin(CraftServer.java:494) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at org.bukkit.craftbukkit.v1_16_R2.CraftServer.enablePlugins(CraftServer.java:408) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at net.minecraft.server.v1_16_R2.MinecraftServer.loadWorld(MinecraftServer.java:435) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at net.minecraft.server.v1_16_R2.DedicatedServer.init(DedicatedServer.java:216) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:808) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[server.jar:git-Spigot-57bbdd8-b8dd5ec]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
     
  2. Offline

    timtower Moderator Moderator

    @Ugonnadie Your plugin.yml has "glide" while you are using "joust" in the code, make sure that they are the same.
     
  3. Offline

    Ugonnadie

    Thank You, it worked.
     

Share This Page