Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<File.au3>
- #include <GUIConstantsEx.au3>
- #include <FileConstants.au3>
- #include <File.au3>
- $gui = GUICreate("Minecraft Updater", 430, 150)
- global $path = @AppDataDir &"\.minecraft\saves\world\"
- $box1 = GUICtrlCreateInput($path,15,10, 400)
- $search = GUICtrlCreateButton("Update",175,100,80)
- GUISetState(@SW_SHOW, $gui)
- global $commands = 33
- global $tags = 8
- global $lib[$commands][2][$tags] = [ _
- [["scoreboard", "players","tag","","add","","",""],["","","tag","*","add","*","*","*"]], _
- [["scoreboard", "players","tag","","remove","","",""],["","","tag","*","remove","*","*","*"]], _
- [["scoreboard", "teams","","","","","",""],["team","","*","*","*","*","*","*"]], _
- [["gamemode","0","","","","","",""],["gamemode","survival","*","*","*","*","*","*"]], _
- [["gamemode","1","","","","","",""],["gamemode","creative","*","*","*","*","*","*"]], _
- [["gamemode","2","","","","","",""],["gamemode","adventure","*","","","","*","*"]], _
- [["gamemode","3","","","","","",""],["gamemode","spectator","*","","","","*","*"]], _
- [["gamemode","s","","","","","",""],["gamemode","survival","*","*","*","*","*","*"]], _
- [["gamemode","c","","","","","",""],["gamemode","creative","*","*","*","*","*","*"]], _
- [["gamemode","a","","","","","",""],["gamemode","adventure","*","","","","*","*"]], _
- [["gamemode","s","","","","","",""],["gamemode","spectator","*","","","","*","*"]], _
- [["effect","","clear","","","","",""],["effect clear","*","","","","","*","*"]], _
- [["effect","","","","","","",""],["effect give","*","*","*","*","*","*","*"]], _
- [["execute","","","","","function","",""],["execute","*","*","*","*","run function","*","*"]], _
- [["execute","","","","","say","",""],["execute","*","*","*","*","run say","*","*"]], _
- [["execute","","","","","scoreboard","",""],["execute","*","*","*","*","run scoreboard","*","*"]], _
- [["execute","","","","","gamemode","",""],["execute","*","*","*","*","run gamemode","*","*"]], _
- [["execute","","","","","execute","",""],["execute","*","*","*","*","run execute","*","*"]], _
- [["execute","","","","","fill","",""],["execute","*","*","*","*","run fill","*","*"]], _
- [["execute","","","","","playsound","",""],["execute","*","*","*","*","run playsound","*","*"]], _
- [["execute","","","","","replaceitem","",""],["execute","*","*","*","*","run replaceitem","*","*"]], _
- [["execute","","","","","tag","",""],["execute","*","*","*","*","run tag","*","*"]], _
- [["execute","","","","","team","",""],["execute","*","*","*","*","run tp","*","*"]], _
- [["execute","","","","","tp","",""],["execute","*","*","*","*","run tp","*","*"]], _
- [["execute","","","","","effect","",""],["execute","*","*","*","*","run effect","*","*"]], _
- [["execute","","","","","clone","",""],["execute","*","*","*","*","run clone","*","*"]], _
- [["execute","","","","","entitydata","",""],["execute","*","*","*","*","run entitydata","*","*"]], _
- [["execute","","","","","give","",""],["execute","*","*","*","*","run give","*","*"]], _
- [["execute","","~","~","~","","",""],["execute as","*","at @s","","","*","*","*"]], _
- [["detect","","","","","-1","",""],["detect","*","*","*","*","","*","*"]], _
- [["detect","","","","","","function",""],["detect","*","*","*","*","*","run function","*"]], _
- [["detect","","","","","","",""],["if block","*","*","*","*","*","*","*"]], _
- [["xp","","","","","","",""],["experience add","*","*","*","*","*","*","*"]] _
- ]
- global $short = 9
- global $shortlib[$short][2] = [ _
- ["m=","gamemode="], _
- ["l=","level="], _
- ["lm=","level="], _
- ["r=","distance="], _
- ["rx=","x_rotation"], _
- ["ry=","y_rotation"], _
- ["c=","limit="], _
- ["m=","gamemode="], _
- ["entitydata","data merge entity"] _
- ]
- global $clean = 6
- global $cleanlib[$clean][2] = [ _
- ["as as","as"], _
- ["at at","at"], _
- ["@s[]","@s"], _
- ["@a[]","@a"], _
- ["@e[]","@e"], _
- ["@p[]","@p"] _
- ]
- main()
- Func main()
- While 1
- Switch GUIGetMsg()
- case $GUI_EVENT_CLOSE, $idOK
- ExitLoop
- case $search
- global $path = GUICtrlRead($box1)
- program($path)
- EndSwitch
- WEnd
- EndFunc
- func program($path)
- $path = fileupdate()
- ConsoleWrite($path&@CRLF)
- $filelist = _FileListToArrayRec($path,"*",1,1,0,2)
- if not @error then
- for $file = 1 to $filelist[0]
- ConsoleWrite($filelist[$file]&@crlf)
- global $linelist
- _FileReadToArray($filelist[$file],$linelist)
- if not @error and $linelist[0] > 0 then
- for $o = 1 to $linelist[0]
- ;~ ConsoleWrite(@CRLF&$linelist[$o])
- replace($linelist[$o])
- $string = shortreplace($string)
- $string = score($string)
- $string = clean($string)
- _FileWriteToLine($filelist[$file], $o, "" & $string, true)
- Next
- EndIf
- next
- EndIf
- exit
- EndFunc
- func fileupdate()
- $exists = _FileListToArray($path&"\datapacks\","*",2,true)
- if $exists >= 1 Then
- $path = $path&"\datapacks\"
- Else
- DirCreate($path & "datapacks\auto_update\data\auto_update\functions")
- _FileCreate($path & "\datapacks\auto_update\pack.mcmeta")
- FileWrite($path & "\datapacks\auto_update\pack.mcmeta",'{"pack": {"pack_format": 3, "description": " "}}')
- DirCopy($path&"\data\functions",$path & "\datapacks\auto_update\data\auto_update\functions")
- ConsoleWrite($path & "\datapacks\auto_update\pack.mcmeta"&@CRLF)
- $path = $path&"\datapacks\"
- EndIf
- return $path
- EndFunc
- func replace($line)
- global $string = ""
- $line = StringReplace($line," /"," ")
- $words = StringSplit($line," ")
- if $words[0] == 0 Then
- return 0
- endif
- ;~ consolewrite($line&@crlf)
- for $position = 1 to $words[0]
- for $command = 0 to $commands -1
- $index = 0
- $length = $tags
- if $length < $words[0] - $position then
- $length = $words[0] - $position
- endif
- while ($index < $tags and $lib[$command][0][$index] == "") or (($index < $tags) and (($position + $index <= $words[0]) and ($words[$position+$index] == $lib[$command][0][$index]))) ;tags match / search tag blank ("")
- ;~ consolewrite($index & @crlf)
- $index += 1
- ;~ consolewrite($lib[$command][0][$index-1] &" matching "&$index-1&@CRLF)
- WEnd
- ;~ consolewrite("POSITION"& $position & @crlf)
- if $index == $tags Then
- ;~ consolewrite("TRIGGERED "&$line & @crlf)
- for $cnt = 0 to $tags - 1
- if $lib[$command][1][$cnt] <> "*" and $position+$cnt<=$words[0] then
- ;~ ConsoleWrite($words[$position+$cnt]& " -> ")
- $words[$position+$cnt] = $lib[$command][1][$cnt]
- ;~ ConsoleWrite($words[$position+$cnt]&@crlf)
- endif
- Next
- ;~ consolewrite("POSITION"& $position & @crlf)
- endif
- ;~ next
- Next
- next
- for $m = 1 to $words[0]
- ;~ ConsoleWrite(@CRLF&""& $wordlist[$m])
- if $words[$m] <> "" Then
- if $string <> "" then
- $string = $string & " "
- endif
- $string = $string & $words[$m]
- EndIf
- next
- if $string = "" Then
- $string = " "
- EndIf
- EndFunc
- func shortreplace($string)
- for $i = 0 to $short -1
- ;~ ConsoleWrite($shortlib[$i][0]&@CRLF)
- ;~ ConsoleWrite($shortlib[$i][1]&@CRLF)
- ;~ ConsoleWrite($i&@CRLF)
- $search = "[" & $shortlib[$i][0]
- $replace = "[" & $shortlib[$i][1]
- $string = StringReplace($string,$search,$replace)
- $search = ","&$shortlib[$i][0]
- $replace = ","&$shortlib[$i][1]
- $string = StringReplace($string,$search,$replace)
- next
- return $string
- EndFunc
- func clean($string)
- for $i = 0 to $clean -1
- $search = $cleanlib[$i][0]
- $replace = $cleanlib[$i][1]
- $string = StringReplace($string,$search,$replace)
- ;~ ConsoleWrite($search&@CRLF)
- $search = $cleanlib[$i][0]
- $replace = $cleanlib[$i][1]
- $string = StringReplace($string,$search,$replace)
- next
- return $string
- EndFunc
- func score($string)
- $words = StringSplit($string," ")
- $return = ""
- $ret = ""
- local $scores[100][3] ; name, min, max
- $scoreindex = 0
- ;~ $selector = $subwords[0] & "["
- if $words[0] >= 1 then
- for $i=1 to $words[0]
- for $p = 0 to 99
- $scores[$p][0] = ""
- $scores[$p][1] = null
- $scores[$p][2] = null
- next
- $ret = ""
- if StringInStr(StringTrimRight($words[$i],stringlen($words[$i])-3),"@") then
- $subwords = StringSplit($words[$i]," ,[]")
- $ret &= $subwords[1] & "["
- ;~ ######datatags########
- if ($i >= 2 and $words[$i-1] == "tag") or ($i>=4 and $words[$i-3] == "scoreboard") Then
- if $i+3 <= $words[0] and StringInStr($words[$i+3],"{") <> 0 Then
- $ret &= "nbt=" & $words[$i+3]
- $words[$i+3] = ""
- EndIf
- EndIf
- ;~ ######datatags########
- for $m = 1 to $subwords[0]
- if StringInStr($subwords[$m],"score_") then
- $subwords[$m] = StringTrimLeft($subwords[$m],6)
- $pos = StringInStr($subwords[$m],"_min=")
- if ($pos) >= 1 then
- $scores[$scoreindex][1] = StringTrimLeft($subwords[$m],$pos+4) ; trim until only score is left
- ;~ consolewrite($scores[$scoreindex][1]& @crlf)
- Else
- $pos = StringInStr($subwords[$m],"=")
- $scores[$scoreindex][2] = StringTrimLeft($subwords[$m],$pos) ; trim until only score is left
- ;~ consolewrite($scores[$scoreindex][2]& @crlf)
- EndIf
- ;~ ConsoleWrite($pos&"###"&$subwords[$m]& " "& stringlen($subwords[$m]) - $pos&@CRLF)
- $scores[$scoreindex][0] = StringTrimRight($subwords[$m],(stringlen($subwords[$m]) - ($pos-1))) ; trim until only name left
- ;~ ConsoleWrite($scores[$scoreindex][0]&@crlf)
- $scoreindex +=1
- $subwords[$m] = ""
- Else
- if $m >= 2 and $subwords[$m] <> "" then
- $ret &= $subwords[$m] & ","
- endif
- endif
- next
- $scr = sort($scores)
- if $scr <> null Then
- $ret &= $scr&","
- EndIf
- if (StringTrimLeft($ret,stringlen($ret)-1) == ",") Then
- $ret = StringTrimRight($ret,1)
- EndIf
- $ret &= "] "
- Else
- $ret &= $words[$i] & " "
- EndIf
- $return &= $ret
- next
- EndIf
- return($return)
- ;~ consolewrite($ret& @crlf)
- EndFunc
- func sort($arr)
- $index = 0
- ;~ consolewrite($arr[1][2]& @crlf)
- $return = "scores={"
- while $arr[$index][0] <> "" and $index <100
- ;~ consolewrite($arr[$index][0]& @crlf)
- for $i= $index to 99
- if $arr[$index][0] == $arr[$i][0] and $i<> $index Then
- $arr[$index][1] += $arr[$i][1]
- $arr[$index][2] += $arr[$i][2]
- $arr[$i][0] = ""
- $arr[$i][1] = 0
- $arr[$i][2] = 0
- ;~ ConsoleWrite($arr[$index][0]&" "&$arr[$index][1]&" "&$arr[$index][2] & @crlf)
- EndIf
- Next
- $index += 1
- wend
- for $index= 0 to 99
- if $arr[$index][0] <> "" Then
- if $return <> "scores={" Then
- $return &= ","
- endif
- $return &= $arr[$index][0]
- $return &= "="
- $return &= $arr[$index][1]
- $return &= ".."
- $return &= $arr[$index][2]
- ;~ ConsoleWrite($arr[$index][0]&" "&$arr[$index][1]&" "&$arr[$index][2] & @crlf)
- endif
- next
- StringTrimRight($return,1) ; remove the last ","
- $return &= "}"
- if $return == "scores={}" Then
- $return = null
- EndIf
- ;~ consolewrite($return& @crlf)
- return $return
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement