Skip to content

Instantly share code, notes, and snippets.

@AtomicBlom
Created July 17, 2017 11:31
Show Gist options
  • Save AtomicBlom/44b0a61adb7f89d3157b209d6e8f3d74 to your computer and use it in GitHub Desktop.
Save AtomicBlom/44b0a61adb7f89d3157b209d6e8f3d74 to your computer and use it in GitHub Desktop.
Minecraft Server Chat Parser
if ($args.Length -eq 0) {
Write-Error "Please provide a filename at the command line"
exit
}
$file = $args[0]
if (-not (Test-Path $file)) {
Write-Error "File not found: $file"
exit
}
$ColourMap = @{
[char]"0" = [System.ConsoleColor]::Black;
[char]"1" = [System.ConsoleColor]::DarkBlue;
[char]"2" = [System.ConsoleColor]::DarkGreen;
[char]"3" = [System.ConsoleColor]::DarkCyan;
[char]"4" = [System.ConsoleColor]::DarkRed;
[char]"5" = [System.ConsoleColor]::DarkMagenta;
[char]"6" = [System.ConsoleColor]::DarkYellow;
[char]"7" = [System.ConsoleColor]::Gray;
[char]"8" = [System.ConsoleColor]::DarkGray;
[char]"9" = [System.ConsoleColor]::Blue;
[char]"a" = [System.ConsoleColor]::Green;
[char]"b" = [System.ConsoleColor]::Cyan;
[char]"c" = [System.ConsoleColor]::Red;
[char]"d" = [System.ConsoleColor]::Magenta;
[char]"e" = [System.ConsoleColor]::Yellow;
[char]"f" = [System.ConsoleColor]::White;
[char]"r" = [System.ConsoleColor]::White;
}
Get-Content $file -Tail 1 -Wait |
Where { $_.Contains("[CHAT]") } |
foreach {
$LineTime = ([System.DateTime]::Now.ToString())
Write-Host -NoNewline "[$LineTime] "
$Foreground = [System.ConsoleColor]::White
([string]$_).Substring(([string]$_).IndexOf("[CHAT]") + 7) -split "(§.)" | % {
$token = [string]$_
if ($token.StartsWith("§")) {
$item = $token.Chars(1)
if ($ColourMap.ContainsKey($item)) {
$Foreground = $ColourMap.Get_Item($item)
}
} else {
if ($Foreground -eq $null) {
$Foreground = $ColourMap.Get_Item("r");
}
Write-Host -ForegroundColor $Foreground -NoNewline $token
}
}
Write-Host
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment