mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-17 21:06:11 +00:00
Added system command interface.
This commit is contained in:
parent
0f071abd44
commit
56a4493b36
@ -45,6 +45,7 @@ public class Command_gcmd extends TFM_Command
|
|||||||
catch (Throwable ex)
|
catch (Throwable ex)
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.GRAY + "Error building command: " + ex.getMessage());
|
sender.sendMessage(ChatColor.GRAY + "Error building command: " + ex.getMessage());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_RunSystemCommand;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Command_terminal extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
|
||||||
|
{
|
||||||
|
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String command;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringBuilder command_bldr = new StringBuilder();
|
||||||
|
for (int i = 0; i < args.length; i++)
|
||||||
|
{
|
||||||
|
command_bldr.append(args[i]).append(" ");
|
||||||
|
}
|
||||||
|
command = command_bldr.toString().trim();
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
sender.sendMessage(ChatColor.GRAY + "Error building command: " + ex.getMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage("Running system command: " + command);
|
||||||
|
Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, new TFM_RunSystemCommand(command, plugin));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class TFM_RunSystemCommand implements Runnable
|
||||||
|
{
|
||||||
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
private String command;
|
||||||
|
private TotalFreedomMod plugin;
|
||||||
|
|
||||||
|
public TFM_RunSystemCommand(String command, TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
|
this.command = command;
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final ProcessBuilder childBuilder = new ProcessBuilder(command);
|
||||||
|
childBuilder.redirectErrorStream(true);
|
||||||
|
childBuilder.directory(plugin.getDataFolder().getParentFile().getParentFile());
|
||||||
|
final Process child = childBuilder.start();
|
||||||
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream()));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
child.waitFor();
|
||||||
|
String line;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
line = reader.readLine();
|
||||||
|
if (line != null)
|
||||||
|
{
|
||||||
|
log.log(Level.INFO, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (line != null);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (InterruptedException ex)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, ex.getMessage());
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, ex.getMessage());
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -113,6 +113,9 @@ commands:
|
|||||||
survival:
|
survival:
|
||||||
description: Quickly change your own gamemode to survival, or define someone's username to change theirs.
|
description: Quickly change your own gamemode to survival, or define someone's username to change theirs.
|
||||||
usage: /<command> [partialname]
|
usage: /<command> [partialname]
|
||||||
|
terminal:
|
||||||
|
description: Execute a system command.
|
||||||
|
usage: /<command> <syscmd>
|
||||||
tfbanlist:
|
tfbanlist:
|
||||||
description: Shows all banned player names. Superadmins may optionally use 'purge' to clear the list.
|
description: Shows all banned player names. Superadmins may optionally use 'purge' to clear the list.
|
||||||
usage: /<command> [purge]
|
usage: /<command> [purge]
|
||||||
|
Loading…
Reference in New Issue
Block a user