Solved Server Command Executer

Discussion in 'Plugin Development' started by CaptainGoobla, Jun 16, 2014.

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

    CaptainGoobla

    Hello there. I need help on my plugin. I'm trying to make the server execute a command once a command is executed. It's suppose to add a suffix with the arguments.
    Code:java
    1. package me.CaptainGoobla.SuffixMood;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class SuffixMood extends JavaPlugin {
    10. public final Logger logger = Logger.getLogger("Minecraft");
    11. public static SuffixMood plugin;
    12.  
    13. @Override
    14. public void onDisable() {
    15. this.logger.info("[SuffixMood] SuffixMood has been enabled!");
    16. }
    17.  
    18. @Override
    19. public void onEnable() {
    20. this.logger.info("[SuffixMood] SuffixMood has been disabled!");
    21.  
    22. }
    23. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){
    24. if(cmd.getName().equalsIgnoreCase("mood")){
    25. this.getServer()//CommandExectuter code goes here, but what is it?
    26. .("pex user " + sender + "prefix '&b[Mood:" + args.length == 0 + "&b] '");
    27. }
    28. return false;
    29. }
    30. }
    31.  
     
  2. Offline

    xTigerRebornx

  3. Offline

    mythbusterma

    Use Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), <command goes here>)
     
  4. Offline

    CaptainGoobla

    mythbusterma I did what you said but I got a error with this:
    The method dispatchCommand(CommandSender, String) in the type Server is not applicable for the arguments (ConsoleCommandSender, boolean)
     
  5. Offline

    mythbusterma

    .....why were you trying to feed a boolean as a command?
     
  6. Offline

    CaptainGoobla

    I'm horrible at coding, I'm just trying to do my best.
     
  7. Offline

    mythbusterma

    It needs to be a String representing a command like "pex adduser mythbusterma admin" or something of that nature.
     
  8. Offline

    CaptainGoobla

    But I need to make it so that the 1st argument is the suffix

    For example:
    [(SUFFIX_GOES_HERE)]
     
  9. Offline

    mythbusterma

    I'm not sure I quite understand what you're trying to do, if you need to put strings together, use the "+" operator.
     
  10. Offline

    CaptainGoobla

    That's what I did...

    This is my code so far:
    Code:java
    1. package me.CaptainGoobla.SuffixMood;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class SuffixMood extends JavaPlugin {
    10. public final Logger logger = Logger.getLogger("Minecraft");
    11. public static SuffixMood plugin;
    12.  
    13. @Override
    14. public void onDisable() {
    15. this.logger.info("[SuffixMood] SuffixMood has been enabled!");
    16. }
    17.  
    18. @Override
    19. public void onEnable() {
    20. this.logger.info("[SuffixMood] SuffixMood has been disabled!");
    21.  
    22. }
    23. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
    24. if(cmd.getName().equalsIgnoreCase("mood"))
    25. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "pex user " + sender + "prefix '&b[Mood: " + args.length == 0 + "&b] '");
    26. return false;
    27. }
    28. }
    29.  


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

    CaptainGoobla

    Um... hello?
     
  12. Offline

    PluginStudios

    CaptainGoobla Uhh... You add args.length == 0. Did you mean to make it the args instead of check what the arguments are?
     
  13. Offline

    CaptainGoobla

    What do you mean? I wanted the first argument to be the suffix
    Example: /mood SUFFIX_GOES_HERE
    Should I have put args.length == 1?
     
  14. Offline

    Drew1080

    CaptainGoobla

    Since the variable args is an Array of Strings you want to get the element at the first index in the array by:
    args[0]

    args.length returns an integer based on the number of elements in the Array.
     
  15. Offline

    CaptainGoobla

    Oh, I wonder why I put that.
    That problem is solved, but for some reason, its not working :/
     
  16. Offline

    Gater12

  17. Offline

    CaptainGoobla

    This is my current code:
    Code:java
    1. package me.CaptainGoobla.SuffixMood;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class SuffixMood extends JavaPlugin {
    10. public final Logger logger = Logger.getLogger("Minecraft");
    11. public static SuffixMood plugin;
    12.  
    13. @Override
    14. public void onDisable() {
    15. this.logger.info("[SuffixMood] SuffixMood has been enabled!");
    16. }
    17.  
    18. @Override
    19. public void onEnable() {
    20. this.logger.info("[SuffixMood] SuffixMood has been disabled!");
    21.  
    22. }
    23. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
    24. if(cmd.getName().equalsIgnoreCase("mood")){
    25. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "pex user " + sender + " prefix '&b[Mood: " + args[0] + "&b] '");
    26. }
    27. return true;
    28. }
    29. }


    Hello?

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

    CaptainGoobla

    Please, I need it for my server.
     
  19. Offline

    Zupsub

    You probably want to do
    ... + sender.getName() + ....
    instead of ... + sender + ...

    However, it might work, I don't know the toString() implementation atm.
     
Thread Status:
Not open for further replies.

Share This Page