I cant Get it to work!

Discussion in 'Plugin Development' started by killerzz1, Apr 21, 2014.

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

    killerzz1

    Hi there i am trying to make a plugin so a player can type /brb and it will brodcast "Playername will be right back" but when i export it to my test server and when i do /brb it just says to me /brb i dont know how to fix this here is my code :


    package me.killerzz1.brb;

    import org.bukkit.plugin.java.JavaPlugin;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class Main extends JavaPlugin {

    public void onEnable()
    {
    System.out.println("BRB Is Active");
    }

    public void onDisable()
    {
    System.out.println("BRB Is Not Active");
    }


    public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args) {
    if(cmd.getName().equalsIgnoreCase("brb")){
    if(!(sender instanceof Player))
    {
    if(!(sender instanceof org.bukkit.command.ConsoleCommandSender))
    {
    sender.sendMessage(ChatColor.RED + "Error: You can't do that from there!");
    }else
    {
    if(args.length > 1)
    {
    for (int i = 0; i < args.length; i++) {
    }
    Bukkit.broadcastMessage(ChatColor.GREEN + "[AFK]" + ChatColor.GOLD + getName() + " " +"Will Be Right Back");

    return true;
    }

    return false;
    }

    }
    }
    return false;
    }
    }
     
  2. Offline

    Gater12

    killerzz1
    The method is onCommand not onCommand1
     
  3. Offline

    killerzz1

    ok and is that what is making it do that ?
     
  4. Offline

    Gater12

  5. Offline

    killerzz1

    ok i have done that and it is still just doing /brb when i do the command
     
  6. Offline

    Maurdekye

    killerzz1 I'm pretty sure you're getting problems from the if(!(sender instanceof org.bukkit.command.ConsoleCommandSender)) line. Try reworking that.
     
  7. Offline

    killerzz1

    and how would you do that?
     
  8. Offline

    Gater12

    killerzz1
    Will only execute if there is more than 1 argument. You do not have any function for if the argument is none.
     
  9. Offline

    killerzz1

    ok so how would i make it so if a player types a command it does a broadcast ?
     
  10. This should work:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label,
    2. String[] args) {
    3. if (label.equalsIgnoreCase("brb")) {
    4. if (sender instanceof Player) {
    5. Bukkit.broadcastMessage(ChatColor.GREEN + "[AFK]"
    6. + ChatColor.GOLD + getName() + " "
    7. + "Will Be Right Back");
    8.  
    9. return true;
    10. } else if (sender instanceof org.bukkit.command.ConsoleCommandSender) {
    11. sender.sendMessage(ChatColor.RED
    12. + "Error: You can't do that from there!");
    13.  
    14. return true;
    15. }
    16. }
    17. return false;
    18. }


    In all serious, you have a bunch of unneeded stuff in there. You mayyyy want to go learn some more Java. =p.

    ~Josh
     
  11. Offline

    ZodiacTheories

    Joshuaknight1998
    killerzz1

    You have alot missing in there -

    1. So the Console is going to be AFK?
    Code:java
    1. if(!(sender instanceof Player)) {
    2. sender.sendMessage("You must be a Player!");
    3. return true;


    2.
    Code:java
    1. if(label.equalsIgnoreCase("brb)) {
    I think
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("brb")) {
    is better

    3. You don't do
    Code:java
    1. if(sender instanceof org.bukkit.command.ConsoleCommandSender) {
    just do
    Code:java
    1. if(!(sender instanceof Player)) {


    4. Where is your casting to a Player?

    5.
    Code:java
    1. + ChatColor.GOLD + getName()
    - What getName - again, cast to a Player

    Sorry if this seems a bit harsh :p
     
  12. Offline

    chingo247

    also you don't override any methods,

    onEnable()
    onDisable()
    onCommand()

    must be overriden, add the @Override annotation above them
     
  13. Offline

    killerzz1

    well im new to java so you know
     
Thread Status:
Not open for further replies.

Share This Page