How to check the player Who use command

Discussion in 'Plugin Development' started by Dumpper Pig, Feb 15, 2017.

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

    Dumpper Pig

    Hello , I'm writing a plugin to check a player who use the command !
    I want to check the player Who are using the command in case with : "sw join (name of the game)" then if a player use that , the console will run a command with "pg clear + (name of the player who use that command)
    This is my code
    Is it something wrong in my code ?
    Code:
    package com.danny.tutorial;
    
    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 Tutorial extends JavaPlugin {
    
        public void onEnable(){
            getLogger().info("Disable PG Enable!");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("sw")){
                Player player = (Player) sender;
                if(args[0].equalsIgnoreCase(" join ") && args[1].equalsIgnoreCase("skywell")){
                    Bukkit.dispatchCommand(getServer().getConsoleSender(), "pg clear "+ player.getName());
                }
            }
            return false;
        }
    }
    
     
  2. Online

    timtower Administrator Administrator Moderator

    @Dumpper Pig Return true if your command ran successfully.
    Check if the sender is a player before casting to one.
    The args[0] will never have spaces around it.
    You don't need to log your own plugin.
     
  3. Offline

    Dumpper Pig

    Thank you !
    And i try to do what you told but not work
    Code:
    package com.danny.tutorial;
    
    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 Tutorial extends JavaPlugin {
    
        public void onEnable(){
            getLogger().info("Disable PG Enable!");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("sw")){
                if(sender instanceof Player){
                Player player = (Player) sender;
                if(args[0].equalsIgnoreCase("join") && args[1].equalsIgnoreCase("skywell")){
                    Bukkit.dispatchCommand(getServer().getConsoleSender(), "pg clear "+ player.getName());
                }
            }
        }
            return false;
    }
    }
     
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    Dumpper Pig

    Yes :(
     
  6. Online

    timtower Administrator Administrator Moderator

    @Dumpper Pig What doesn't work? How isn't it working? Do you get errors? Do you get messages?
     
  7. Offline

    Dumpper Pig

    No error on my console , the command "pg clear playername" it is a command to clear the effect of player but when i try do the "sw join Skywell" not thing happend the effect didn't clear
     
  8. Online

    timtower Administrator Administrator Moderator

    @Dumpper Pig Print a message when the command is running.
     
  9. Offline

    Dumpper Pig

    How to print a message on the console sorry for ask that question i'm beginer !
     
  10. Online

    timtower Administrator Administrator Moderator

  11. Offline

    Mathias Eklund

    @Dumpper Pig
    You are gonna have an obscene amount of problems if you do not learn basic Java before you jump into working with Bukkit/Spigot.

    I'd recommend learning from thenewboston.com.
     
  12. Offline

    Dumpper Pig

    Thank you but i already know about java
     
  13. Online

    timtower Administrator Administrator Moderator

    Then you should know how to print to the console.
     
  14. Offline

    Zombie_Striker

    I don't think you own danny.com. Use a domain you do own, or use the format me.<name>.<project>.

    Click THIS and THIS.
     
Thread Status:
Not open for further replies.

Share This Page