Send commands to console

Discussion in 'Resources' started by Redecouverte, Feb 2, 2011.

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

    Redecouverte

    *This is a temporary fix for sending console commands until bukkit officially supports it*

    This function allows you to queue console commands.
    -> It is thread-safe, so you can call it from any thread.

    For this to work you have to add craftbukkit as library to your project.

    Code:
    /*
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU Lesser General Public License as published
        by the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
        GNU Lesser General Public License for more details.
    
        You should have received a copy of the GNU Lesser General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */
    
    import java.lang.reflect.Field;
    import org.bukkit.Server;
    import org.bukkit.craftbukkit.CraftServer;
    import net.minecraft.server.MinecraftServer;
    
    public class ConsoleHelper {
    
        public static boolean queueConsoleCommand(Server server, String cmd) {
    
            try {
                Field f = CraftServer.class.getDeclaredField("console");
                f.setAccessible(true);
                MinecraftServer ms = (MinecraftServer) f.get(server);
    
                if ((!ms.g) && (MinecraftServer.a(ms))) {
                    ms.a(cmd, ms);
                    return true;
                }
    
            } catch (Exception e) {
            }
    
            return false;
        }
    
    }
    
     
  2. Offline

    Timberjaw

    Awesome. I was looking for a way to do this.
     
  3. Offline

    MonsieurApple

    Thank you so so much.

    Could you possibly provide a license, like maybe GPL v3?
     
  4. Offline

    Redecouverte

    There you go :)
     
  5. Offline

    unv_annihlator

    @Redecouverte Ok so is this still the best way to do this, or did Bukkit get a method to do it?
     
Thread Status:
Not open for further replies.

Share This Page