Run commands on server start

Discussion in 'Archived: Plugin Requests' started by Little Kits, Sep 1, 2013.

  1. Offline

    Little Kits

    Plugin category: Server Managment

    Suggested name: StartupCMD

    What I want: I would like to see a plugin that automatically runs commands that are configured in a config.yml file. The config.yml should be able to support multiple commands.

    An example config is shown below:
    Code:
    ##############################
    ###  StartupCMD by Author  ###
    ###  Version: 1.0          ###
    ##############################
     
    Commands:
      - 'vt run restart:reset'
    I have many more commands that I need to run than just the one listed, that is why I need multiple command support

    Ideas for commands: /startupcmd reload - Reloads configuration file

    Ideas for permissions: startupcmd.reload - Allows access to /startupcmd reload command

    When I'd like it by: As soon as possible

    My reason for requesting this plugin is because it is not yet possible on VariableTriggers plugin, and I can not find another plugin that does this exact thing anywhere else.
     
  2. Offline

    McMhz

    Well, I could do this.. But I got no time right now.
    I'll try my best when I come back ;)
     
  3. Offline

    timtower Administrator Administrator Moderator

  4. Offline

    dainiusb

  5. Offline

    Little Kits

    CommandHelper spams my console with alot of crap. Literally spams like a nodus spam hack xD

    I would like this to have only the 1 feature requested above. Maybe a developer can grab the source code from Autorun Commands, then modify it a little to make it work, and then publish it to BukkitDev and post a link here.

    MANIFEST.MS
    Show Spoiler
    Code:text
    1. Manifest-Version: 1.0


    StartUpCmds.class
    Show Spoiler
    Code:java
    1. package com.45zeldafan.StartUpCmds;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Server;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.configuration.ConfigurationSection;
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class StartUpCmds extends JavaPlugin
    12. {
    13. public void onEnable()
    14. {
    15. saveDefaultConfig();
    16. getConfig();
    17. boolean verbose = getConfig().getBoolean("verbose");
    18. getLogger().info("Running StartUp Commands" + (verbose ? " VERBOSE OUTPUT ENABLED" : ""));
    19. for (String s : getConfig().getConfigurationSection("suc").getKeys(true))
    20. if (getConfig().getConfigurationSection("suc").getBoolean(s, false)) {
    21. s = s.replace(".", " ");
    22. if (verbose) getLogger().info("Running: " + s);
    23. getServer().dispatchCommand(getServer().getConsoleSender(), s);
    24. }
    25. }
    26.  
    27. public void onDisable()
    28. {
    29. getConfig();
    30. boolean verbose = getConfig().getBoolean("verbose");
    31. getLogger().info("Running ShutDown Commands" + (verbose ? " VERBOSE OUTPUT ENABLED" : ""));
    32. for (String s : getConfig().getConfigurationSection("sdc").getKeys(true))
    33. if (getConfig().getConfigurationSection("sdc").getBoolean(s, false)) {
    34. s = s.replace(".", " ");
    35. if (verbose) getLogger().info("Running: " + s);
    36. getServer().dispatchCommand(getServer().getConsoleSender(), s);
    37. }
    38. }
    39.  
    40. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    41. {
    42. int i;
    43. if (cmd.getName().equalsIgnoreCase("startup")) {
    44. if ((args.length == 0) && (sender.hasPermission("StartUpCmds.list"))) {
    45. for (String s : getConfig().getConfigurationSection("suc").getKeys(true))
    46. if (getConfig().getConfigurationSection("suc").getBoolean(s, false)) {
    47. s = "/" + s.replace(".", " ");
    48. sender.sendMessage(s);
    49. }
    50. return true;
    51. }
    52. if ((args[0].equalsIgnoreCase("add")) && (sender.hasPermission("StartUpCmds.startup"))) {
    53. if (args.length == 1) { sender.sendMessage("Usage: /startup add [command]"); return true; }
    54. String path = new String();
    55. for (int i = 1; i < args.length; i++) {
    56. path = path + "." + args[i];
    57. }
    58. path = "suc" + path.replace("/", "");
    59. getConfig().set(path, Boolean.valueOf(true));
    60. saveConfig();
    61. return true;
    62. }
    63. if ((args[0].equalsIgnoreCase("del")) && (sender.hasPermission("StartUpCmds.startup"))) {
    64. if (args.length == 1) {
    65. sender.sendMessage("Usage: /startup del [command]");
    66. sender.sendMessage("Technically it only disables it");
    67. return true;
    68. }
    69. String path = new String();
    70. for (i = 1; i < args.length; i++) {
    71. path = path + "." + args[i];
    72. }
    73. path = "suc" + path.replace("/", "");
    74. getConfig().set(path, Boolean.valueOf(false));
    75. saveConfig();
    76.  
    77. return true;
    78. }
    79. }
    80. if (cmd.getName().equalsIgnoreCase("shutdown")) {
    81. if ((args.length == 0) && (sender.hasPermission("StartUpCmds.list"))) {
    82. for (String s : getConfig().getConfigurationSection("sdc").getKeys(true))
    83. if (getConfig().getConfigurationSection("sdc").getBoolean(s, false)) {
    84. s = "/" + s.replace(".", " ");
    85. sender.sendMessage(s);
    86. }
    87. return true;
    88. }
    89. if ((args[0].equalsIgnoreCase("add")) && (sender.hasPermission("StartUpCmds.shutdown"))) {
    90. if (args.length == 1) { sender.sendMessage("Usage: /shutdown add [command]"); return true; }
    91. String path = new String();
    92. for (int i = 1; i < args.length; i++) {
    93. path = path + "." + args[i];
    94. }
    95. path = "sdc" + path.replace("/", "");
    96. getConfig().set(path, Boolean.valueOf(true));
    97. saveConfig();
    98. return true;
    99. }
    100. if ((args[0].equalsIgnoreCase("del")) && (sender.hasPermission("StartUpCmds.shutdown"))) {
    101. if (args.length == 1) {
    102. sender.sendMessage("Usage: /shutdown del [command]");
    103. sender.sendMessage("Technically it only disables it");
    104. return true;
    105. }
    106. String path = new String();
    107. for (int i = 1; i < args.length; i++) {
    108. path = path + "." + args[i];
    109. }
    110. path = "sdc" + path.replace("/", "");
    111. getConfig().set(path, Boolean.valueOf(false));
    112. saveConfig();
    113.  
    114. return true;
    115. }
    116. }
    117. return false;
    118. }
    119. }[/i][/i][/i][/i]


    Now just plugin.yml and config.yml and it should work.

    If a kind developer would please modify the code above into a 1.6.2 version update, and upload the jar with a link here, I will love you forever. Honestly though, I will give you $15.00 worth of donator points on my KitPvP server


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

    timtower Administrator Administrator Moderator

    That code is already 1.6.2 compatible...
     
  7. Offline

    Little Kits

    So can someone compile it into a plugin for me please? I don't know how
     
  8. Offline

    timtower Administrator Administrator Moderator

    Ask the person who gave it to you
     
  9. Offline

    Little Kits

    I asked them for the plugin, they said no, but that they would give me the source code. So I am asking someone on bukkit to compile it because I have no knowledge of it.
     
  10. Offline

    GaaTavares

    You can decompile ._.
     
  11. Offline

    General

    timtower likes this.

Share This Page