Says weird stuff on command?

Discussion in 'Plugin Development' started by Joshuak52, Apr 18, 2014.

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

    Joshuak52

    I made a restart plugin for my Prison server so when they want to restart they can and it will take away there money/rank and spawn them, But players get an error on this command can someone help?


    Code:java
    1. if(cmd.getName().equalsIgnoreCase("Restart")) {
    2. Player p = (Player) sender;
    3. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "Manuadd " + p.getName() + " A");
    4. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco set " + p.getName() + " 0");
    5. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + p.getName());
    6. Bukkit.broadcastMessage(ChatColor.AQUA + "Everyone " + p.getName() + " Reset his rank! He is now A");
    7. }


    and the error
    http://gyazo.com/2256f07612fbb87980c90284f21b2299
     
  2. Offline

    Smartloser

    Player p =(Player) sender;

    Try putting that before the if statement.
     
  3. Offline

    Joshuak52

    Smartloser I can't that messes up other commands though
     
  4. Offline

    Smartloser

    Joshuak52 Why would you define the player inside the command itself?
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd,
    3. String commandLabel, String[] args)
    4. {
    5. if (sender instanceof Player)
    6. Player p = (Player)sender;
    7. else if (sender instanceof ConsoleCommandSender)
    8. {
    9. // blablabla
    10. }
    11. }
    12.  

    How exactly it messes your code?
     
  5. Offline

    Joshuak52

    Smartloser I always put it inside my command.. and because I have other commands with the player thing also
     


  6. try
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("Restart")) {
    2. if(sender instanceof Player){
    3. Player p = (Player) sender;
    4. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "Manuadd " + p.getName() + " A");
    5. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco set " + p.getName() + " 0");
    6. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + p.getName());
    7. Bukkit.broadcastMessage(ChatColor.AQUA + "Everyone " + p.getName() + " Reset his rank! He is now A");
    8. }
    9. }
     
  7. Offline

    Joshuak52

    @Hendrik_the_best I still get same error :(

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  8. Offline

    Badeye

    That is no error, the palyer has no permissions to execute the command. Check your plugin.yml, the command should be listed there. Now if there is a permission argument like
    Code:
    permission: <plugin name>.restart
    completly remove the line. It is not needed for the plugin.yml file. Now save the file, reload the project in eclipse, export it and try it again. Now everybody can execute the command and no message should pop up.

    If you only want operators to be able to execute the command, clinch your command with
    Code:java
    1. if(sender.isOp()){
    2. //You command stuff
    3. }
     
Thread Status:
Not open for further replies.

Share This Page