Hello, I'm fairly new here and based on the help that i've seen people give I though this would be a great place to ask!
Basically, I'm new with coding, so I decided to work with Minecraft - specific a Minecraft Server Starter. It has a built in text box to display all the stuff that the console would normally display and an input tetbox to use commands.
I have it so you can either use the Normal Minecraft Server or a Bukkit server. Basically, when I run minecraft.jar it works perfectly, I get the Output from the console and I can input commands.
When I use craftbukkit.jar (bukkit) I get the Output of the console fine, but I can't input any commands... I can't figure out why it's doing this!
Honestly I have no idea what part could be causing the problem, so I'll post my whole Form.
Imports System.Net
Imports System.IO
Imports System.Diagnostics
Public Class Form1
Dim WithEvents WC As New WebClient
Private psi As ProcessStartInfo
Private cmd As Process
Private Delegate Sub InvokeWithString(ByVal text As String)
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
ProgressBar2.Value = 0
Button3.Text = "Updating..."
If CheckBox1.Checked Then
WC.DownloadFileAsync(New Uri("http://repo.bukkit.org/content/groups/repo/org/bukkit/craftbukkit/1.0.1-R1/craftbukkit-1.0.1-R1.jar"), "craftbukkit.jar")
Else
WC.DownloadFileAsync(New Uri("https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar?"), "minecraft.jar")
End If
End Sub
Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged
ProgressBar2.Value = e.ProgressPercentage
If e.ProgressPercentage = 100 Then
If CheckBox1.Checked Then
Button3.Text = "Bukkit Updated"
Else
Button3.Text = "Minecraft Updated"
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
startTimer.Start()
stopTimer.Stop()
txtConsoleOut.Clear()
If java6.Checked Then
psi = New ProcessStartInfo("C:\Program Files\Java\jre6\bin\java.exe")
ElseIf java7.Checked Then
psi = New ProcessStartInfo("C:\Program Files\Java\jre7\bin\java.exe")
End If
Dim systemencoding As System.Text.Encoding = _
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.UseShellExecute = False ' Required for redirection
If CheckBox1.Checked Then
.Arguments = "-Xincgc -Xmx1024M -jar craftbukkit.jar"
Else
.Arguments = "-Xincgc -Xmx1024M -jar minecraft.jar nogui"
End If
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemencoding ' Use OEM encoding for console applications
.StandardErrorEncoding = systemencoding
End With
' EnableraisingEvents is required for Exited event
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf Async_Data_Received
AddHandler cmd.OutputDataReceived, AddressOf Async_Data_Received
cmd.Start()
' Start async reading of the redirected streams
' Without these calls the events won't fire
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
Me.txtConsoleIn.Select()
End Sub
' This sub gets called in a different thread so invokation is required
Private Sub Async_Data_Received(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
Me.Invoke(New InvokeWithString(AddressOf Sync_Output), e.Data)
End Sub
Private Sub Sync_Output(ByVal text As String)
txtConsoleOut.AppendText(text & Environment.NewLine)
txtConsoleOut.ScrollToCaret()
End Sub
' Sending console commands here
Private Sub txtConsoleIn_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtConsoleIn.KeyPress
If e.KeyChar = ControlChars.Cr Then
cmd.StandardInput.WriteLine(txtConsoleIn.Text)
txtConsoleIn.Clear()
End If
End Sub
Private Sub startTimer_Tick(sender As System.Object, e As System.EventArgs) Handles startTimer.Tick
ProgressBar1.Increment(+7)
Label1.Text = "Starting Up..."
If ProgressBar1.Value = 100 Then
Label1.Text = "Running..."
End If
End Sub
Private Sub stopTimer_Tick(sender As System.Object, e As System.EventArgs) Handles stopTimer.Tick
ProgressBar1.Increment(-7)
Label1.Text = "Stopping..."
If ProgressBar1.Value = 0 Then
Label1.Text = "Stopped"
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
stopTimer.Start()
startTimer.Stop()
cmd.StandardInput.WriteLine("save-all")
cmd.StandardInput.WriteLine("stop")
End Sub
Private Sub java6_Click(sender As System.Object, e As System.EventArgs) Handles java6.Click
If My.Computer.FileSystem.FileExists("C:\Program Files\Java\jre6\bin\java.exe") Then
java6.Checked = True
Else
MsgBox("Java 6 Not Found - Make sure you have it installed correctly.")
End If
End Sub
Private Sub java7_Click(sender As System.Object, e As System.EventArgs) Handles java7.Click
If My.Computer.FileSystem.FileExists("C:\Program Files\Java\jre7\bin\java.exe") Then
java7.Checked = True
Else
MsgBox("Java 7 Not Found - Make sure you have it installed correctly.")
End If
End Sub
Private Sub CheckBox1_CheckedStateChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckStateChanged
If My.Computer.FileSystem.FileExists("craftbukkit.jar") Then
CheckBox1.Checked = True
Else
MsgBox("Bukkit Not Installed!")
End If
End Sub
End Class