Solved Command just returns the usage

Discussion in 'Plugin Development' started by G4merXsquaD, Jun 25, 2019.

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

    G4merXsquaD

    I tried many things but is always just return the usage, also no errors everything works fine but this
    can someone help me pls
    this is my commandexecutor:

    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
                org.bukkit.Location location = player.getLocation();
                location.setY(location.getY()+10);
                player.teleport(location);
                player.sendMessage("TP UP 10 BLOCKS BOIIIIII");
                return true;
            } else {
                sender.sendMessage("No consoles allowed in the wild west...");
                return false;
            }
        }
    EDIT: I have tried replacing the return thing and sending messages at every step even at the beginning before if (sender instanceof Player) { and that doesn't send anything either so that means my /tpup command isn't doing anything only show the usage. can anyone help me. If you need a source code ask me
     
    Last edited: Jun 25, 2019
  2. Offline

    Zombie_Striker

    @G4merXsquaD
    1. If you have to specifics the Location object, you most likely imported the wrong location value. Check your imports and remove the other Location class.
    2. Returning false displays the usage. If you do not want the usage, return true.
     
  3. Offline

    G4merXsquaD

    what location value do i need to import then?
    i tried returning true but it didn't work
     
  4. Offline

    KarimAKL

    org.bukkit.Location
    What is your current code? I think it only gives you the usage if you are returning false or haven't registered the command.
     
  5. Offline

    G4merXsquaD

    this is the code (sorry if it is a bit messy):
    a moderator removed the url so here is my main script
    Code:
    package com.gmail.hugovandekuilen1234567890.ListOPlayers;
    
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class ListOPlayers extends JavaPlugin {
        @Override
        public void onEnable() {
            getLogger().info("Loading ListOPlayers");
            // loading stuff...
            getCommand("tpup").setExecutor(new MyPluginCommandExecutor(this));
            //this.getCommand("tpup").setExecutor(new MyPluginCommandExecutor(this));
            getLogger().info("Hello little boiii, me big boi!1i!1i plugin has bin enabled");
        }
        @Override
        public void onDisable() {
            getLogger().info("Hello little boiii, me big boi!1i!1i plugin has bin disabled");
        }
    }
    
    and here is my command executor
    Code:
    package com.gmail.hugovandekuilen1234567890.ListOPlayers;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class MyPluginCommandExecutor implements CommandExecutor {
        @SuppressWarnings("unused")
        private ListOPlayers plugin;
    
        public MyPluginCommandExecutor(ListOPlayers plugin) {
            this.plugin = plugin; // Store the plugin in situations where you need it.
            Bukkit.getServer().getLogger().info("TPUP command enabled");
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Bukkit.getServer().getLogger().info(ChatColor.GREEN + "A command got executed!");
            if (cmd.getName().equalsIgnoreCase("tpup")) {
                Bukkit.getServer().getLogger().info(ChatColor.GREEN + "/TPUP Got executed!");
                if (sender instanceof Player) {
                    Bukkit.getServer().getLogger().info(ChatColor.GREEN + "/TPUP Got executed! by a player!");
                    Player player = (Player) sender;
                    org.bukkit.Location location = player.getLocation();
                    location.setY(location.getY()+10);
                    player.teleport(location);
                    player.sendMessage("TP UP 10 BLOCKS BOIIIIII");
                } else {
                    Bukkit.getServer().getLogger().info(ChatColor.GREEN + "/TPUP Got executed! by a console");
                    sender.sendMessage("No consoles allowed in the wild west...");
                }
                return true;
            }
            Bukkit.getServer().getLogger().info(ChatColor.RED + "/TPUP Got ended!");
            return false;
        }
    }
    
    I started a fresh new project and copied everything and now it works:eek:

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

Share This Page