Wierd issue when console performs commands.

Discussion in 'Plugin Development' started by omon23, Aug 19, 2014.

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

    omon23

    Hello,

    I am making a plugin for a friend. He wants the plugin to run commands through the console when a player joins. It all works fine, but when the command is run through the console and when the player joins, for some reason, the raw command shows up in chat, even though the command has been performed.

    Like this:
    rawmessageerror.PNG

    In the config there are some variables (in this command %player%) and that has worked successfully in putting the players name in place of %player%.

    Here is my class:
    Code:java
    1. package me.omon23;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import net.milkbowl.vault.permission.Permission;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.plugin.RegisteredServiceProvider;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class JoinCommands extends JavaPlugin implements Listener{
    15. public static Permission permission = null;
    16.  
    17. public void onEnable() {
    18. loadConfig();
    19. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20. setupPermissions();
    21. }
    22.  
    23. public void onDisable() {
    24.  
    25. }
    26.  
    27. public void loadConfig() {
    28. getConfig().addDefault("commands", "");
    29. getConfig().options().copyDefaults(true);
    30. saveConfig();
    31.  
    32. }
    33.  
    34. @EventHandler
    35. public void onJoin(PlayerJoinEvent event) {
    36. ArrayList<String> list = (ArrayList<String>) getConfig().getStringList("commands");
    37. int length = list.size();
    38. if (length == 0) {
    39. getLogger().info("[JoinCommands] There are no commands to run");
    40. }
    41. int i;
    42. for (i = 0; i < length; i++) {
    43. String com = list.get(i);
    44. String group = permission.getPrimaryGroup(event.getPlayer());
    45. String command = com.replaceAll("%group%", group).replaceAll("%player%", event.getPlayer().getName());
    46. event.getPlayer().sendMessage(command);
    47. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
    48. }
    49.  
    50.  
    51. }
    52.  
    53. public boolean setupPermissions()
    54. {
    55. RegisteredServiceProvider<net.milkbowl.vault.permission.Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
    56. if (permissionProvider != null) {
    57. permission = permissionProvider.getProvider();
    58. }
    59. return (permission != null);
    60. }
    61.  
    62.  
    63. }
    64.  


    It also implements vault for groups(as my friend requested).

    Any help is appreciated!

    - omon23
     
  2. Try removing
    event.getPlayer().sendMessage(command); (line 46)
    Because that sends the command
     
  3. Offline

    Gerov

    omon23 You need to make console preform a command,

    Code:java
    1. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
     
    The Fancy Whale likes this.
Thread Status:
Not open for further replies.

Share This Page