We need your assitance once more guys?!?

Discussion in 'Plugin Development' started by FlameHead269, Jan 15, 2011.

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

    FlameHead269

    Hello, its Flame and 1337. We, have gotten then plugin to run without any error.(No Compliing errors)
    so we needed ur assitance on why wouldnt the commands work
    tell me if this is right or not. We are sorry if we are bothering you but we are very eager to get this finished your help will be highly appriciated!!!
    Thanks,
    FlameHead269,1377
    Code:
    public void onPlayerCommand(PlayerChatEvent event) {
    String[] split = event.getMessage().split(" ");
    Player player = event.getPlayer();
    final String command = split[0];
    if (command.equalsIgnoreCase("/time day")){
    plugin.getServer().setTime(0);
    player.sendMessage("good morning");

    }
    if (command.equalsIgnoreCase("/time night")){
    plugin.getServer().setTime(12000);
    player.sendMessage("good night");

    }
    else if (command.equalsIgnoreCase("/time")){
    player.sendMessage(Color.RED + "incorrect use of /time");
    player.sendMessage(Color.RED + "try /time day and /time night");
    }


    }}
     
  2. Code:
    if (!event.isCancelled() && command.equalsIgnoreCase("/time")){
        if(split[1].equalsIgnoreCase("day")){
            plugin.getServer().setTime(0);
            player.sendMessage("good morning");
        }else if(split[1].equalsIgnoreCase("night")){
            plugin.getServer().setTime(12000);
            player.sendMessage("good night");
        }else{
            player.sendMessage(Color.RED + "incorrect use of /time");
            player.sendMessage(Color.RED + "try /time day and /time night");
        }
        event.setCancelled(true);
    }
    You are splitting the message string every time there is a space, so command only holds the first word.

    EDIT: formatting, this forum software hates me
    EDIT 2: To include the stuff i mentioned below.
     
  3. Offline

    FlameHead269

    oooo thank you sir!
     
  4. I'm not certain on the way things work in Bukkit, but I believe you will also want to check that the event hasn't already been cancelled before using it, and cancel the event after you have used it. I'll update my above post to reflect this, and could someone who knows better than me confirm this?
     
  5. Offline

    1337

    thanks very very much :)
     
Thread Status:
Not open for further replies.

Share This Page