Solved Plugin development error

Discussion in 'Plugin Development' started by EthanGarey, Aug 25, 2022.

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

    EthanGarey

    Console when I entered the tp command
    Code:
    [17:18:48 INFO]: EthanGarey issued server command: /tp
    [17:18:48 ERROR]: null
    org.bukkit.command.CommandException: Cannot execute command 'tp' in plugin BetterCommands v1.0 Release - plugin is disabled.
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_19_R1.CraftServer.dispatchCommand(CraftServer.java:911) ~[paper-1.19.2.jar:git-Paper-132]
            at org.bukkit.craftbukkit.v1_19_R1.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:64) ~[paper-1.19.2.jar:git-Paper-132]
            at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:264) ~[paper-1.19.2.jar:?]
            at net.minecraft.commands.Commands.performCommand(Commands.java:305) ~[?:?]
            at net.minecraft.commands.Commands.performCommand(Commands.java:289) ~[?:?]
            at net.minecraft.server.network.ServerGamePacketListenerImpl.performChatCommand(ServerGamePacketListenerImpl.java:2298) ~[?:?]
            at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$20(ServerGamePacketListenerImpl.java:2252) ~[?:?]
            at net.minecraft.util.thread.BlockableEventLoop.lambda$submitAsync$0(BlockableEventLoop.java:59) ~[?:?]
            at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?]
            at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.19.2.jar:git-Paper-132]
            at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
            at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
            at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1361) ~[paper-1.19.2.jar:git-Paper-132]
            at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:185) ~[paper-1.19.2.jar:git-Paper-132]
            at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
            at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1338) ~[paper-1.19.2.jar:git-Paper-132]
            at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1331) ~[paper-1.19.2.jar:git-Paper-132]
            at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
            at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1309) ~[paper-1.19.2.jar:git-Paper-132]
            at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1197) ~[paper-1.19.2.jar:git-Paper-132]
            at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:305) ~[paper-1.19.2.jar:git-Paper-132]
            at java.lang.Thread.run(Thread.java:833) ~[?:?]
    My main file
    Code:
    package BetterCommands;
    
    
    import Commands.Fly;
    import Commands.Teleport;
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class Main extends JavaPlugin {
    
        @Override
        public void onEnable() {
            // Plugin startup logic
            Bukkit.getLogger().info("Hello World!");
            getCommand("tp").setExecutor(new Teleport());
            getCommand("fly").setExecutor(new Fly());
        }
    
        @Override
        public void onDisable() {
            // Plugin shutdown logic
            Bukkit.getLogger().info("Shutting Down!");
        }
    }
    
    The teleport and other commands
    Code:
    package Commands;
    
    import net.md_5.bungee.api.ChatColor;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Teleport extends JavaPlugin {
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "This plugin is for players only!");
                return true;
            }
    
            Player p = (Player) sender;
    
            if (cmd.getName().equalsIgnoreCase("tp")) {
                if (args.length == 0) {
                    p.sendMessage(ChatColor.RED + "Please specify a player.");
                    return true;
                }
                Player target = Bukkit.getServer().getPlayer(args[0]);
                if (target == null) {
                    p.sendMessage(ChatColor.RED + "Could not find player " + args[0] + "!");
                    return true;
                }
                p.teleport(target.getLocation());
                return true;
            }
            return true;
        }
    }
    plugin.yml
    Code:
    name: BetterCommands
    version: '${project.version}'main: BetterCommands.Main
    api-version: 1.19
    authors: [ EthanGarey ]
    commands:
    tp:
    usage: /<command>
    aliases: [teleport]
    description: Teleport to other players.
    permission-message: "&4&lYou do not have access to that command"permission: permissions.commands.teleport.others
    fly:
    description: Toggles flight for player.
    permission: permissions.commands.flight.toggle
    permission-message: "&4&lYou do not have access to that command"usage: /fly (optional player)
    
    upload_2022-8-25_17-31-23.png upload_2022-8-25_17-31-50.png
     
    Last edited by a moderator: Aug 25, 2022
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Strahan

    It said the plugin is disabled, so as tim said you must have other errors in your log during startup to show why the plugin puked.

    Also you really don't need to send enable/disable messages. Bukkit does that for you already, so manually doing it just clutters the log.
     
  4. Offline

    mehboss

    The problem is that when you check to see if the argument of the command is only /tp instead of /tp <player> you return true instead of return false.... :)

    Same goes for if (target == null). Should be return false; rather than return true;

    Goodness.. you should also follow naming conventions for your packages.........
    https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
     
    Last edited: Aug 26, 2022
  5. Offline

    EthanGarey

    https://pastebin.com/ZUiVdKVn

    And I just started plugin development, I just moved from script to this. I'm still getting used to it.

    How do I fix this?

    It's my first plugin, I'm just- experimenting.

    Solved, I had to change
    public class Teleport extends JavaPlugin {
    to
    public class Teleport implements CommandExecutor {
    (I figured that out on my own :).)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 27, 2022
Thread Status:
Not open for further replies.

Share This Page