Console Commands! NEED HELP TOO MUCH!

Discussion in 'Plugin Development' started by xHungerZzz, Aug 28, 2014.

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

    xHungerZzz

    Hello guys!
    I try to run a console command through a command!
    Please help me... why it doesn't work?
    If i do this, i finish my whole project for a server :oops:
    I read some articles and i saw that i have to register a event... how i do this? (Coding since 3 days ago)

    The code witch i use:
    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "spawn " + HunterKitPlayer.getName());
    Here is the image:
    [​IMG]
     
  2. Offline

    Jimfutsu

    ITaco xHungerZzz
    How does that help?
    Hes not using listeners, hes using commands.
    using dispatchCommand, the args are (Player to dispatch command, command).
    currently, you are making your console try to teleport to spawn. This would cause errors.
     
  3. Offline

    xHungerZzz

    Ok... can you please tell me how to fix this?
     
  4. Offline

    nlthijs48

    xHungerZzz Simply use your variable 'HunterKitPlayer' instead of 'Bukkit.getConsoleSender()' and then the command will be executed as that player.
     
  5. Offline

    TheHandfish

  6. Offline

    xHungerZzz

  7. Offline

    nateracecar5

    What I did when I tried to accomplish this was:
    Code:java
    1. player.chat("/spawn");



    I know it's not the best, probably the worst thing you can do, but I guarantee it works.

    Also, just noticed this: You are making your console do "/spawn name".
    What it should be is:
    Code:java
    1. Bukkit.getServer().dispatchCommand(HunterKitPlayer, "spawn " + HunterKitPlayer.getName());


    See, the first argument should be the player to execute the command, and the second should be the command to execute (If I'm correct). You getting the console to execute the command via the console, which was your issue. Now that you have HunterKitPlayer, which is your variable to represent the players you are looping, it will go through each player and do the command.

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

    xHungerZzz

    Thank you so much! I will try it!
     
  9. Offline

    nateracecar5

Thread Status:
Not open for further replies.

Share This Page